provide 'getScripts()' XML-RPC method
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2046 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
525050654a
commit
607782d907
3 changed files with 22 additions and 21 deletions
|
@ -38,9 +38,15 @@ class IPythonScript(Interface):
|
||||||
automatically.
|
automatically.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
title = schema.TextLine(
|
||||||
|
title=_(u"Title"),
|
||||||
|
description=_(u"A descriptive title of the script."),
|
||||||
|
required=False,
|
||||||
|
default=u''
|
||||||
|
)
|
||||||
parameters = schema.TextLine(
|
parameters = schema.TextLine(
|
||||||
title=_(u"Parameters"),
|
title=_(u"Parameters"),
|
||||||
description=_(u"Space-separated list of parameter names."),
|
description=_(u"Comma-separated list of parameter names."),
|
||||||
required=False,
|
required=False,
|
||||||
default=u''
|
default=u''
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,6 +31,8 @@ from zope.traversing.browser import absoluteURL
|
||||||
from cybertools.pyscript.plot import registerImage
|
from cybertools.pyscript.plot import registerImage
|
||||||
|
|
||||||
|
|
||||||
|
# not used (yet?):
|
||||||
|
|
||||||
class RWrapper(object):
|
class RWrapper(object):
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
|
@ -45,27 +47,12 @@ class RWrapper(object):
|
||||||
value = removeAllProxies(value)
|
value = removeAllProxies(value)
|
||||||
return RWrapper(value)
|
return RWrapper(value)
|
||||||
|
|
||||||
|
|
||||||
rx = RWrapper(r)
|
rx = RWrapper(r)
|
||||||
|
|
||||||
with_mode = RWrapper(rpy.with_mode)
|
with_mode = RWrapper(rpy.with_mode)
|
||||||
#as_py = RWrapper(rpy.as_py)
|
#as_py = RWrapper(rpy.as_py)
|
||||||
|
|
||||||
|
|
||||||
def gdd(**kw):
|
|
||||||
r.library('GDD')
|
|
||||||
filename = os.tempnam(None, 'rplot')
|
|
||||||
robj = r.GDD(filename, type='jpg', **kw)
|
|
||||||
return filename + '.jpg', robj
|
|
||||||
|
|
||||||
def graphics(**kw):
|
|
||||||
context = kw.pop('context', None)
|
|
||||||
request = kw.pop('request', None)
|
|
||||||
fn, robj = gdd(**kw)
|
|
||||||
key = registerImage(fn)
|
|
||||||
return '%s/@@plot?image=%s' % (absoluteURL(context, request), key)
|
|
||||||
|
|
||||||
|
|
||||||
class RStat(object):
|
class RStat(object):
|
||||||
|
|
||||||
def __init__(self, context, request):
|
def __init__(self, context, request):
|
||||||
|
|
|
@ -89,11 +89,16 @@ class PythonScript(Contained, Persistent):
|
||||||
|
|
||||||
_v_compiled = None
|
_v_compiled = None
|
||||||
|
|
||||||
|
title = u''
|
||||||
parameters = u''
|
parameters = u''
|
||||||
|
source = u''
|
||||||
|
contentType=u'text/plain'
|
||||||
|
|
||||||
def __init__(self, source=u'', parameters=u'', contentType=u'text/plain'):
|
def __init__(self, title=u'', parameters=u'', source=u'',
|
||||||
|
contentType=u'text/plain'):
|
||||||
"""Initialize the object."""
|
"""Initialize the object."""
|
||||||
super(PythonScript, self).__init__()
|
super(PythonScript, self).__init__()
|
||||||
|
self.title = title
|
||||||
self.source = source
|
self.source = source
|
||||||
self.contentType = contentType
|
self.contentType = contentType
|
||||||
self.parameters = parameters or u''
|
self.parameters = parameters or u''
|
||||||
|
@ -164,12 +169,12 @@ class Function(object):
|
||||||
"""A compiled function.
|
"""A compiled function.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
parameters = ''
|
parameters = []
|
||||||
|
|
||||||
def __init__(self, source, parameters='', filename='<string>'):
|
def __init__(self, source, parameters='', filename='<string>'):
|
||||||
lines = []
|
lines = []
|
||||||
if parameters:
|
if parameters:
|
||||||
self.parameters = str(parameters).split()
|
self.parameters = [str(p).strip() for p in parameters.split(',')]
|
||||||
#print '*** Function.parameters:', repr(self.parameters)
|
#print '*** Function.parameters:', repr(self.parameters)
|
||||||
lines.insert(0, 'def dummy(): \n pass')
|
lines.insert(0, 'def dummy(): \n pass')
|
||||||
for line in source.splitlines():
|
for line in source.splitlines():
|
||||||
|
@ -182,6 +187,7 @@ class Function(object):
|
||||||
def __call__(self, args, globals):
|
def __call__(self, args, globals):
|
||||||
globals['__builtins__'] = SafeBuiltins
|
globals['__builtins__'] = SafeBuiltins
|
||||||
for idx, p in enumerate(self.parameters):
|
for idx, p in enumerate(self.parameters):
|
||||||
|
# TODO: handle parameters with default values like ``attr=abc``
|
||||||
globals[p] = args[idx]
|
globals[p] = args[idx]
|
||||||
exec self.code in globals, None
|
exec self.code in globals, None
|
||||||
|
|
||||||
|
@ -198,12 +204,14 @@ class ScriptContainer(BTreeContainer):
|
||||||
|
|
||||||
implements(IScriptContainer)
|
implements(IScriptContainer)
|
||||||
|
|
||||||
unrestricted_objects = ('rstat') # not used (yet)
|
unrestricted_objects = ('rstat',) # not used (yet)
|
||||||
|
|
||||||
|
def getItems(self):
|
||||||
|
return self.values()
|
||||||
|
|
||||||
def updateGlobals(self, globs):
|
def updateGlobals(self, globs):
|
||||||
if HAS_R:
|
if HAS_R:
|
||||||
from cybertools.pyscript import rstat
|
from cybertools.pyscript import rstat
|
||||||
#globs['rstat'] = rstat
|
|
||||||
context = globs['context']
|
context = globs['context']
|
||||||
request = globs['request']
|
request = globs['request']
|
||||||
globs['rstat'] = rstat.RStat(context, request)
|
globs['rstat'] = rstat.RStat(context, request)
|
||||||
|
|
Loading…
Add table
Reference in a new issue