[Libreoffice-commits] core.git: scripting/source
Laurent Godard
laurent.godard at cncc.fr
Tue Apr 24 23:37:16 UTC 2018
scripting/source/pyprov/pythonscript.py | 34 ++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
New commits:
commit aa45e2745f14c5626fe163939dc7d101efe9d1cd
Author: Laurent Godard <laurent.godard at cncc.fr>
Date: Tue Apr 24 16:05:18 2018 +0200
tdf#117202 - parse function name to get arguments
they are then aggregated to the other and passed to the function
Change-Id: I158a747de9c22d50716fc066074a593b4928d6bf
Reviewed-on: https://gerrit.libreoffice.org/53424
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py
index ef131b3c1dab..5844ebe8912c 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()
+ # retrieve 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)]
+ # retrieve 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 )
More information about the Libreoffice-commits
mailing list