2010-01-12 14:15:14 -06:00
|
|
|
'''job.py must be executed by a "zopectl run" command and, as single arg,
|
|
|
|
must get a string with the following format:
|
|
|
|
|
2010-01-14 10:54:18 -06:00
|
|
|
<ZopeAdmin><PloneInstancePath>:<ApplicationName>:<ToolMethodName>[:<args>].
|
2010-01-12 14:15:14 -06:00
|
|
|
|
2010-01-14 10:54:18 -06:00
|
|
|
<ZopeAdmin> is the userName of the Zope administrator for this instance.
|
2010-01-12 14:15:14 -06:00
|
|
|
<PloneInstancePath> is the path, within Zope, to the Plone Site object (if
|
|
|
|
not at the root of the Zope hierarchy, use '/' as
|
|
|
|
folder separator);
|
|
|
|
|
|
|
|
<ApplicationName> is the name of the Appy application;
|
|
|
|
|
|
|
|
<ToolMethodName> is the name of the method to call on the tool in this
|
|
|
|
Appy application;
|
|
|
|
|
|
|
|
<args> (optional) are the arguments to give to this method (only strings
|
|
|
|
are supported). Several arguments must be separated by '*'.'''
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2010-01-14 10:54:18 -06:00
|
|
|
import sys, transaction
|
|
|
|
|
2010-01-12 14:15:14 -06:00
|
|
|
# Check that job.py is called with the right parameters.
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
print 'job.py was called with wrong args.'
|
|
|
|
print __doc__
|
|
|
|
else:
|
|
|
|
command = sys.argv[1]
|
|
|
|
parts = command.split(':')
|
2010-01-14 10:54:18 -06:00
|
|
|
if len(parts) not in (4,5):
|
2010-01-12 14:15:14 -06:00
|
|
|
print 'job.py was called with wrong args.'
|
|
|
|
print __doc__
|
|
|
|
else:
|
|
|
|
# Unwrap parameters
|
2010-01-14 10:54:18 -06:00
|
|
|
if len(parts) == 4:
|
|
|
|
zopeUser, plonePath, appName, toolMethod = parts
|
2010-01-12 14:15:14 -06:00
|
|
|
args = ()
|
|
|
|
else:
|
2010-01-14 10:54:18 -06:00
|
|
|
zopeUser, plonePath, appName, toolMethod, args = parts
|
|
|
|
# Zope was initialized in a minimal way. Complete Zope install.
|
2010-01-12 14:15:14 -06:00
|
|
|
from Testing import makerequest
|
|
|
|
app = makerequest.makerequest(app)
|
2010-01-14 10:54:18 -06:00
|
|
|
# Log as Zope admin
|
|
|
|
from AccessControl.SecurityManagement import newSecurityManager
|
|
|
|
user = app.acl_users.getUserById(zopeUser)
|
|
|
|
if not hasattr(user, 'aq_base'):
|
|
|
|
user = user.__of__(uf)
|
|
|
|
newSecurityManager(None, user)
|
|
|
|
|
2010-01-12 14:15:14 -06:00
|
|
|
# Get the Plone site
|
|
|
|
ploneSite = app # Initialised with the Zope root object.
|
|
|
|
for elem in plonePath.split('/'):
|
|
|
|
ploneSite = getattr(ploneSite, elem)
|
|
|
|
# Get the tool corresponding to the Appy application
|
|
|
|
toolName = 'portal_%s' % appName.lower()
|
|
|
|
tool = getattr(ploneSite, toolName).appy()
|
|
|
|
# Execute the method on the tool
|
|
|
|
if args: args = args.split('*')
|
|
|
|
exec 'tool.%s(*args)' % toolMethod
|
2010-01-14 10:54:18 -06:00
|
|
|
transaction.commit()
|
2010-01-12 14:15:14 -06:00
|
|
|
# ------------------------------------------------------------------------------
|