summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Godard <laurent.godard@cncc.fr>2018-04-24 16:05:18 +0200
committerLaurent Godard <laurent.godard@cncc.fr>2018-04-24 16:45:26 +0200
commit2f3a64081418db291f5dc9eb67aac23066f09b54 (patch)
treedbf20478245ec93f1a4b42d12b0efd514d0f018e
parentb9c46a57c16116ea4beef59abf0fd11b7d6d97a3 (diff)
tdf#117202 - parse function name to get arguments
they are then aggregated to the other and passed to the function Change-Id: I158a747de9c22d50716fc066074a593b4928d6bf
-rw-r--r--scripting/source/pyprov/pythonscript.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py
index ef131b3c1dab..19057f0f227b 100644
--- a/scripting/source/pyprov/pythonscript.py
+++ b/scripting/source/pyprov/pythonscript.py
@@ -743,7 +743,7 @@ class DummyProgressHandler( unohelper.Base, XProgressHandler ):
def push( self,status ):
log.debug( "pythonscript: DummyProgressHandler.push " + str( status ) )
- def update( self,status ):
+ def update( self,status ):
log.debug( "pythonscript: DummyProgressHandler.update " + str( status ) )
def pop( self, event ):
log.debug( "pythonscript: DummyProgressHandler.push " + str( event ) )
@@ -866,12 +866,18 @@ class PackageBrowseNode( unohelper.Base, XBrowseNode ):
class PythonScript( unohelper.Base, XScript ):
- def __init__( self, func, mod ):
+ def __init__( self, func, mod, args ):
self.func = func
self.mod = mod
+ if (args != '' and args is not None):
+ self.args = tuple([x.strip() for x in args.split(",")])
+ else:
+ self.args = None
def invoke(self, args, out, outindex ):
log.debug( "PythonScript.invoke " + str( args ) )
try:
+ if (self.args):
+ args += self.args
ret = self.func( *args )
except UnoException as e:
# UNO Exception continue to fly ...
@@ -883,7 +889,7 @@ class PythonScript( unohelper.Base, XScript ):
# some people may beat me up for modifying the exception text,
# but otherwise office just shows
# the type name and message text with no more information,
- # this is really bad for most users.
+ # this is really bad for most users.
e.Message = e.Message + " (" + complete + ")"
raise
except Exception as e:
@@ -980,6 +986,21 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
def getType( self ):
return self.dirBrowseNode.getType()
+ # retreive function args in parenthesis
+ def getFunctionArguments(self, func_signature):
+ nOpenParenthesis = func_signature.find( "(")
+ if -1 == nOpenParenthesis:
+ function_name = func_signature
+ arguments = ''
+ else:
+ function_name = func_signature[0:nOpenParenthesis]
+ leading = func_signature[nOpenParenthesis+1:len(func_signature)]
+ nCloseParenthesis = leading.find( ")")
+ if -1 == nCloseParenthesis:
+ raise IllegalArgumentException( "PythonLoader: mismatch parenthesis " + func_signature, self, 0 )
+ arguments = leading[0:nCloseParenthesis]
+ return function_name, arguments
+
def getScript( self, scriptUri ):
try:
log.debug( "getScript " + scriptUri + " invoked")
@@ -990,13 +1011,18 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
fileUri = storageUri[0:storageUri.find( "$" )]
funcName = storageUri[storageUri.find( "$" )+1:len(storageUri)]
+ # retreive arguments in parenthesis
+ funcName, funcArgs = self.getFunctionArguments(funcName)
+ log.debug( " getScript : parsed funcname " + str(funcName) )
+ log.debug( " getScript : func args " + str(funcArgs) )
+
mod = self.provCtx.getModuleByUrl( fileUri )
log.debug( " got mod " + str(mod) )
func = mod.__dict__[ funcName ]
log.debug( "got func " + str( func ) )
- return PythonScript( func, mod )
+ return PythonScript( func, mod, funcArgs )
except:
text = lastException2String()
log.error( text )