Package de.oktoflow.platform.tools.lib
Class PythonUtils
java.lang.Object
de.oktoflow.platform.tools.lib.PythonUtils
Some generic Python process helper functions. For now taken over to keep this plugin on Java 8. Considers from
environment
IIP_PYTHON as Python binary to use as well as IIP_PYTHONARGS as additional Python
interpreter arguments. Tries to find Python (python3, python) in system path.- Author:
- Holger Eichelberger, SSE
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns the operating system "PATH" variable.static StringgetPythonArgs(String pythonArgs) Returns the python interpreter arguments either from the string passed in or fromIIP_PYTHONARGS.static FileReturns the Python executable.static FilegetPythonExecutable(String pythonBinary) Returns the Python executable.static StringgetSystemProperty(String property, String dflt) Gets a System property, defaulting todfltif the property is not defined/cannot be read.static final String[]insertArgs(String[] cmd, int pos, String args) Inserts arguments into a (command line) array.static booleanReturns whether we are running on Windows.static voidsetPythonExecutable(File exec) Defines the (global) Python executable.
-
Field Details
-
DEFAULT_PYTHON_EXECUTABLE
-
pythonExecutable
-
-
Constructor Details
-
PythonUtils
public PythonUtils()
-
-
Method Details
-
isOsWindows
public static boolean isOsWindows()Returns whether we are running on Windows.- Returns:
truefor Windows,falseelse
-
getOsPath
Returns the operating system "PATH" variable.- Returns:
- the path variable, empty if not defined/found
-
getSystemProperty
Gets a System property, defaulting todfltif the property is not defined/cannot be read.- Parameters:
property- the system property name- Returns:
- the system property value or
defltif it is not defined/cannot be read
-
setPythonExecutable
Defines the (global) Python executable.- Parameters:
exec- the executable, may be null for dynamically determined
-
getPythonExecutable
Returns the Python executable. We consider the following precedences:- Local python3 in Linux Jenkins installation (for testing, although this is production code; with installation path)
- Local python3 in default Linux installation ("/usr/bin", with installation path)
- The global python executable
setPythonExecutable(File)(with installation path) - The command "python"
- Returns:
- the executable, returns at least "python"; the result may be an absolute path but must not be. Calling
File.getAbsolutePath()on the result may be misleading - if required, use it as string.
-
getPythonExecutable
Returns the Python executable. We consider the following precedences:- Local python3 in Linux Jenkins installation (for testing, although this is production code; with installation path)
- Local python3 in default Linux installation ("/usr/bin", with installation path)
- The global python executable
setPythonExecutable(File)(with installation path) - The command "python"
- Parameters:
pythonBinary- explicitly given path to python binary- Returns:
- the executable, returns at least "python"; the result may be an absolute path but must not be. Calling
File.getAbsolutePath()on the result may be misleading - if required, use it as string.
-
getPythonArgs
Returns the python interpreter arguments either from the string passed in or fromIIP_PYTHONARGS.- Parameters:
pythonArgs- the python interpreter arguments, may be null or empty- Returns:
- the python interpreter arguments, may be null or empty
-
insertArgs
Inserts arguments into a (command line) array.- Parameters:
cmd- the original (command line) arraypos- the position where to insert, call is ignored if the position is outside the arrayargs- the arguments to insert, call is ignored if null or empty, args are split by spaces- Returns:
- the (extended) arguments
-