Advertisement
LukeSavefrogs

Jython get filename

Aug 23rd, 2023
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | Software | 0 0
  1. import re as _re
  2. import os as _os
  3.  
  4. import java.lang.System as System # pyright: ignore[reportMissingImports]
  5.  
  6. def get_filename():
  7.     command = str(System.getProperties().get("sun.java.command"))
  8.     # current_dir = System.getProperty("user.dir")
  9.  
  10.     if command.find("com.ibm.ws.admin.services.WsAdmin") != -1:
  11.         filename_regex = r'-f\s+(.*\.py)'               # wsadmin.sh -f 'filename.py'
  12.     elif command.find("com.vtservices.opat.batch.impl.websphere.RunWasBatch") != -1:
  13.         filename_regex = r'-executeScript\s+(.*\.py)'   # myWasBatch.sh -executeScript 'filename.py'
  14.     else:
  15.         raise Exception("Unsupported CLI command: '%s'" % command)
  16.    
  17.     filename = _re.search(filename_regex, command)
  18.     if filename is None:
  19.         return None
  20.    
  21.     return _os.path.abspath(filename.group(1))
  22.  
  23. if __name__ == '__main__':
  24.     print("Current script is '%s'" % str(get_filename()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement