Python Command-line Interface Processor for MovingCode

Workflow

The python script referenced in the packagedescription.xml under mc:workspace/mc:executableLocation is called with command line arguments. The command line arguments are provided in the order as defined in mc:workspace/mc:executionParameters.

A mc:workspace example
<mc:workspace>
        <mc:workspaceRoot>./bin</mc:workspaceRoot>
        <mc:executableLocation>./myscript.py</mc:executableLocation>
        <mc:containerType>http://gis.geo.tu-dresden.de/movingcode/containerregistry/pythonscript-2.5</mc:containerType>
        <mc:executionParameters>
            <!-- Inputs -->
            <mc:parameter>
                <mc:positionID>1</mc:positionID>
                <mc:functionalInputID>dataset</mc:functionalInputID>
            </mc:parameter>
            <!-- Outputs -->
            <mc:parameter>
                <mc:positionID>2</mc:positionID>
                <mc:functionalOutputID>PDF</mc:functionalOutputID>
            </mc:parameter>
        </mc:executionParameters>
    </mc:workspace>

with parameters (dataset = "/var/data/testdataset1", PDF = "output.pdf") would result in the following execution:
python ./bin/myscript.py /var/data/testdatasets1 output.pdf

The called python script must produce the file "output.pdf" after succesful execution to allow accessing it from the PythonCLIProcessor. This is the basic interaction pattern of the CLI and the python MC package.

Important Notes

Some things have to be taken care of In a linux production environment.
  • Python scripts are run as the user which owns the JVM. This might be the current user, or a service-specific one (e.g. tomcat)
  • service-specific users might have a limited execution path. In particular, executables located under /usr/local/bin and the like might not be accesible by default.
  • This is in general not solvable at the PythonCLIProcessor level, so python MC package developers might provide a workaround:
import os
#add /usr/local/bin to path - the default location of gtcontrol and the like
path = os.getenv("PATH")
os.environ['PATH'] = "/usr/local/bin" + os.pathsep + path

This topic: Geoprocessing > WebHome > MovingCode > PythonCLIProcessor
Topic revision: 25 Jun 2013, DanielNuest
Legal Notice | Privacy Statement


This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback