It's really up to you where you want to store and organize Python code
that you use in a STAX job. If the Python code contains common Python
classes/functions used by multiple STAX jobs, then you will probably want
to store them outside of the STAX jobs. Three ways that you can access
Python code stored in files other than the STAX job xml file are:
1) In a .py file that you can specify when you execute a STAX job via the
EXECUTE request's SCRIPTFILE option and optionally the SCRIPTFILEMACHINE
(these options can also be specified via the STAX Monitor if you use it to
submit STAX jobs). The STAX User's Guide describes these options as
follows:
SCRIPTFILE specifies the fully qualified name of a file containing Python
code to be executed. This is like a <script> element in root <stax>
element in the XML document, but defined when submitting an execute
request, rather than within the XML document. Note that a SCRIPTFILE
parameter specified in an execute request will be executed by the STAX
service after any "global" <script> elements (that is, those contained
directly within the root <stax> element), but before any SCRIPT parameters
are executed. Thus, you can override the value of a variable specified in
a global <script> element by using a SCRIPTFILE parameter in the execute
request. You may specify as many SCRIPTFILE parameters as needed. This
option will resolve STAF variables.
SCRIPTFILEMACHINE specifies the endpoint for the machine where the
SCRIPTFILE(s) are located. If not specified, it defaults to the value
specified for MACHINE. If a MACHINE option was not specified, it assumes
the script file(s) are on the machine submitting the STAX EXECUTE request.
This option will resolve STAF variables.
2) In a .py file that is available on the STAX service machine so that
your STAX job can import classes/functions from it via a <script> element
in your STAX job.
3) In a .py file that your STAX job runs via a <process> element on the
local or a remote system.
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
From: Tennis Smith <tennis_sm...@yahoo.com>
To: staf-users@lists.sourceforge.net,
Date: 11/11/2013 03:08 PM
Subject: [staf-users] When To Export STAX Functionality to Python?
Hi,
I'm struggling with refactoring old stax xml/python code. The one issue
that keeps coming up is when to interleave python in job files and when to
have python routines called externally.
For example,we have a lot of STAX code written like this one (below). It
seems that all of this kind of work could be done in a pure python
function in a utility file somewhere.
Make sense?
-T
Example function:
<function name="createOutputFile">
<function-prolog>
</function-prolog>
<function-no-args/>
<sequence>
<script>
currentContext =
gCurrentRootScriptContextMgr.getCurrentScriptContext()
scriptFileName = currentContext.scrScriptFileName
import os
(filePath, fileName) = os.path.split(scriptFileName)
outFilePath = "Output"
outFileName = "out." + fileName
</script>
<call function="'logSTAXMsgAlways'">"StaxScriptXml-58: Script
File Name is %s" % scriptFileNa
<if expr="filePath != None">
<sequence>
<script>
os.path.normpath(filePath)
outFilePath = os.path.join(filePath, outFilePath)
</script>
<if expr="os.path.isdir(outFilePath)">
<call function="'logSTAXMsgVerbose'">"Output
directory exists"</call>
<else>
<sequence>
<call function="'logSTAXMsgVerbose'">
"Creating Output Directory"</call>
<script>
os.mkdir(outFilePath)
</script>
</sequence>
</else>
</if>
</sequence>
</if>
<script>
outFileName = os.path.join(outFilePath, outFileName)
currentScriptContext.openOutputHandle(outFileName)
</script>
</sequence>
</function>
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models.
Explore
techniques for threading, error checking, porting, and tuning. Get the
most
from the latest Intel processors and coprocessors. See abstracts and
register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users