Kaydet (Commit) aa45e274 authored tarafından Laurent Godard's avatar Laurent Godard Kaydeden (comit) Thorsten Behrens

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/53424Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 0e6999ed
......@@ -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 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment