4.2.20 Python plug-in
Function
This plug-in can execute Python scripts.
Cautionary notes
-
Supported versions of Python is Version 3.x series. The Python plug-in does not support a virtual Python environment.
-
The Python interpreter must be installed on the JP1/AO server before it can be used. To use in a cluster environment, the Python interpreter must be installed on both the active and standby systems.
Version
01.00.01
Tag
Execute Script
Return codes
Return code |
Description |
---|---|
0 |
Ended normally. |
1 |
Python interpreter failed. |
2 |
Python script failed. |
3 |
Python script timed out. |
80 |
Task execution has stopped. |
127 |
An error other than the above occurred. |
Property list
The following table describes the properties.
Property key |
Property name |
Description |
Default value |
I/O type |
Required |
---|---|---|---|---|---|
pythonInterpreterPath |
Python Interpreter Path |
Specifies the path to the Python interpreter that executes the script. |
python |
Input |
R |
scriptBody |
Script Body |
Specifies the Python code. |
-- |
Input |
R |
importedScript |
Imported script |
Specify the methods and constants (strings in Python code) that are shared with other Python plug-ins used in the same service template. |
-- |
Input |
O |
webServiceConnectionCategory |
Web Service Connection Category |
Specify the Web Service Connection category. |
-- |
Input |
O |
webServiceConnectionName |
Web Service Connection Name |
Specify the Web Service Connection name. |
-- |
Input |
O |
timeout |
Time Out |
Specifies the timeout time (in seconds) for the specified script. |
300 |
Input |
O |
inN# |
Script Input (N#) |
Specifies an argument to be passed to the script. |
-- |
Input |
O |
standardOutput |
Standard Output |
Outputs the standard output of the specified script as a character string. |
-- |
Output |
O |
standardErrorOutput |
Standard Error Output |
Outputs the standard error output of the specified script as a character string. |
-- |
Output |
O |
outN# |
Script Output (N#) |
Outputs the value specified for the argument of the "outN#" function in the specified script. |
-- |
Output |
O |
- #
-
N: An integer in the range from 0 to 9
You specify the plug-in input/output properties in the property list. Combinations of service property values, reserved property values, and literal characters can be used for the input properties.
Variables and functions that can be used in the Script Body
The following variables and functions can be used in the Script Body.
Category |
Name |
Description |
||
---|---|---|---|---|
Variable |
inN# |
The value specified for the input property (inN#) is set. The value is interpreted as a character string even if the value is specified as an array or in JSON format. |
||
Function |
outN# (String Value) |
The value passed as the argument of the function is output to the component output property (outN#). |
||
Function |
log (String Value) |
You can output any strings to the tasklog. In this case, choose a log level by adding a specific prefix to the beginning of the string. |
||
Prefix |
[Severe] |
Outputs as log level 0 |
||
[Information] |
Outputs as log level 10 |
|||
[Fine] |
Outputs as log level 20 |
|||
[Finer] |
Outputs as log level 30 |
|||
[Debug] |
Outputs as log level 40 |
|||
(No prefix) |
Outputs as log level 10 (Same as the prefix [Information] ) |
- #
-
N: An integer in the range from 0 to 9
Note that if the following import lines defined by default are deleted from the script, the variables and functions mentioned above cannot be used.
from dnaplugin import in0, in1, in2, in3, in4, in5, in6, in7, in8, in9 from dnaplugin import out0, out1, out2, out3, out4, out5, out6, out7, out8, out9 from dnaplugin import log
Environment variables that can be referenced from the Script Body
Specify a value for the environment variables when executing the script. You can get the values for the following environment variables in the os.environ[key-name] or os.environ.get(key-name) format.
Environment variable |
Description |
Format |
---|---|---|
PLUGIN_PROPERTIES |
Property for the Python plug-in |
JSON format {property-name:value...} |
SERVICE_TEMPLATE_ID |
ID of the service template to which the Python plug-in belongs |
Numerical value |
SERVICE_ID |
ID of the service running the Python plug-in |
Numerical value |
SERVICE_TEMPLATE |
Information about the service template to which the Python plug-in belongs |
JSON format {service-template-attribute:value... } |
SERVICE |
Information about the service running the Python Plug-in |
JSON format {service-attribute:value...} |
WEB_SERVICE_CONNECTIONS |
Settings information for the Web Service Connection. # |
JSON format [{WebServiceConnection-attribute:value...}, ...] |
- #
-
This corresponds to the specified input properties ("Web Service Connection Category" and "Web Service Connection Name") seen in the following table.
Input properties specification
Reference information
Web Service Connection Category
Web Service Connection Name
Value is specified. (Y)
Value is specified. (Y)
Web Service Connection information that coincides with the specified Category and Name
Value is specified. (Y)
Value is not specified. (N)
Web Service Connection information that coincides with the specified Category
Value is not specified. (N)
Value is specified. (Y)
None
Value is not specified. (N)
Value is not specified. (N)
None
About imported scripts
If you want to share methods and constants with other Python plug-ins used in the same service template, define the methods and constants in the importedScript property.
By mapping the importedScript property to the service input property, and then mapping the importedScript properties of other Python plug-ins to the same service input property, you can share the methods and constants defined in the imported script with the Script Body of each Python plug-in.
-
Referencing methods and constants from the Script Body
The methods and constants defined in the imported script can be referenced by using the module name dnaplugin_imported_script from the Script Body.
The import statement is included in the Script Body by default.
-
Functions and environment variables that can be used in the imported script
Functions: The function log() can be used. For details, see the description of the function log() in the table of variables and functions that can be used in the Script Body.
Environment variables: These are the same as the environment variables that can be used in the Script Body. For details, see the table of environment variables that can be referenced from the Script Body.
Sample imported script
- Script Body
# -*- coding: utf-8 -*- import os from dnaplugin import in0, in1, in2, in3, in4, in5, in6, in7, in8, in9 from dnaplugin import out0, out1, out2, out3, out4, out5, out6, out7, out8, out9 from dnaplugin import log from dnaplugin_imported_script import * hoge(CNST)
- Imported script
from dnaplugin import log def hoge(a): log(a + ' from common py!') CNST = 'hoge'