incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r1366950 - /incubator/ooo/trunk/main/scripting/source/pyprov/pythonscript.py
Date Sun, 29 Jul 2012 20:53:49 GMT
Author: pfg
Date: Sun Jul 29 20:53:48 2012
New Revision: 1366950

URL: http://svn.apache.org/viewvc?rev=1366950&view=rev
Log:
#i550055# Simplify pythonscript.py code

author:	hanya

Modified:
    incubator/ooo/trunk/main/scripting/source/pyprov/pythonscript.py

Modified: incubator/ooo/trunk/main/scripting/source/pyprov/pythonscript.py
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/scripting/source/pyprov/pythonscript.py?rev=1366950&r1=1366949&r2=1366950&view=diff
==============================================================================
--- incubator/ooo/trunk/main/scripting/source/pyprov/pythonscript.py (original)
+++ incubator/ooo/trunk/main/scripting/source/pyprov/pythonscript.py Sun Jul 29 20:53:48 2012
@@ -173,7 +173,7 @@ class MyUriHelper:
         else:
             self.m_baseUri = expandUri( self.s_UriMap[location] )
             self.m_scriptUriLocation = location
-        log.isDebugLevel() and log.debug( "initialized urihelper with baseUri="+self.m_baseUri
+ ",m_scriptUriLocation="+self.m_scriptUriLocation )
+        log.debug( "initialized urihelper with baseUri="+self.m_baseUri + ",m_scriptUriLocation="+self.m_scriptUriLocation
)
 
     def getRootStorageURI( self ):
         return self.m_baseUri
@@ -187,20 +187,20 @@ class MyUriHelper:
     def storageURI2ScriptUri( self, storageURI ):
         if not storageURI.startswith( self.m_baseUri ):
             message = "pythonscript: storage uri '" + storageURI + "' not in base uri '"
+ self.m_baseUri + "'"
-            log.isDebugLevel() and log.debug( message )
+            log.debug( message )
             raise RuntimeException( message )
 
         ret = "vnd.sun.star.script:" + \
               storageURI[len(self.m_baseUri)+1:].replace("/","|") + \
               "?language=" + LANGUAGENAME + "&location=" + self.m_scriptUriLocation
-        log.isDebugLevel() and log.debug( "converting storageURI="+storageURI + " to scriptURI="
+ ret )
+        log.debug( "converting storageURI="+storageURI + " to scriptURI=" + ret )
         return ret
 
     def scriptURI2StorageUri( self, scriptURI ):
         try:
             myUri = self.m_uriRefFac.parse(scriptURI)
             ret = self.m_baseUri + "/" + myUri.getName().replace( "|", "/" )
-            log.isDebugLevel() and log.debug( "converting scriptURI="+scriptURI + " to storageURI="
+ ret )
+            log.debug( "converting scriptURI="+scriptURI + " to storageURI=" + ret )
             return ret
         except UnoException, e:
             log.error( "error during converting scriptURI="+scriptURI + ": " + e.Message)
@@ -281,12 +281,12 @@ class ScriptContext(unohelper.Base):
 #    lastRead = sfa.getDateTimeModified( url )
 #    if entry:
 #        if hasChanged( entry.lastRead, lastRead ):
-#            log.isDebugLevel() and log.debug("file " + url + " has changed, reloading")
+#            log.debug("file " + url + " has changed, reloading")
 #        else:
 #            load = False
 #
 #    if load:
-#        log.isDebugLevel() and log.debug( "opening >" + url + "<" )
+#        log.debug( "opening >" + url + "<" )
 #
 #        code = readTextFromStream( sfa.openFileRead( url ) )
 
@@ -296,7 +296,7 @@ class ScriptContext(unohelper.Base):
 #        entry.module.__file__ = url
 #        exec code in entry.module.__dict__
 #        g_modules[ url ] = entry
-#        log.isDebugLevel() and log.debug( "mapped " + url + " to " + str( entry.module )
)
+#        log.debug( "mapped " + url + " to " + str( entry.module ) )
 #    return entry.module
 
 class ProviderContext:
@@ -329,7 +329,7 @@ class ProviderContext:
     def addPackageByUrl( self, url ):
         packageName = self.getPackageNameFromUrl( url )
         transientPart = self.getTransientPartFromUrl( url )
-        log.isDebugLevel() and log.debug( "addPackageByUrl : " + packageName + ", " + transientPart
+ "("+url+")" + ", rootUrl="+self.rootUrl )
+        log.debug( "addPackageByUrl : " + packageName + ", " + transientPart + "("+url+")"
+ ", rootUrl="+self.rootUrl )
         if self.mapPackageName2Path.has_key( packageName ):
             package = self.mapPackageName2Path[ packageName ]
             package.pathes = package.pathes + (url, )
@@ -356,7 +356,7 @@ class ProviderContext:
         if self.rootUrl:
             pos = len( self.rootUrl) +1
             ret = url[0:pos]+url[url.find("/",pos)+1:len(url)]
-        log.isDebugLevel() and log.debug( "getPersistentUrlFromStorageUrl " + url +  " ->
"+ ret)
+        log.debug( "getPersistentUrlFromStorageUrl " + url +  " -> "+ ret)
         return ret
 
     def getStorageUrlFromPersistentUrl( self, url):
@@ -366,7 +366,7 @@ class ProviderContext:
             packageName = url[pos:url.find("/",pos+1)]
             package = self.mapPackageName2Path[ packageName ]
             ret = url[0:pos]+ package.transientPathElement + "/" + url[pos:len(url)]
-        log.isDebugLevel() and log.debug( "getStorageUrlFromPersistentUrl " + url + " ->
"+ ret)
+        log.debug( "getStorageUrlFromPersistentUrl " + url + " -> "+ ret)
         return ret
 
     def getFuncsByUrl( self, url ):
@@ -412,12 +412,12 @@ class ProviderContext:
         lastRead = self.sfa.getDateTimeModified( url )
         if entry:
             if hasChanged( entry.lastRead, lastRead ):
-                log.isDebugLevel() and log.debug( "file " + url + " has changed, reloading"
)
+                log.debug( "file " + url + " has changed, reloading" )
             else:
                 load = False
 
         if load:
-            log.isDebugLevel() and log.debug( "opening >" + url + "<" )
+            log.debug( "opening >" + url + "<" )
 
             src = readTextFromStream( self.sfa.openFileRead( url ) )
             checkForPythonPathBesideScript( url[0:url.rfind('/')] )
@@ -435,7 +435,7 @@ class ProviderContext:
             exec code in entry.module.__dict__
             entry.module.__file__ = url
             self.modules[ url ] = entry
-            log.isDebugLevel() and log.debug( "mapped " + url + " to " + str( entry.module
) )
+            log.debug( "mapped " + url + " to " + str( entry.module ) )
         return  entry.module
 
 #--------------------------------------------------
@@ -474,16 +474,16 @@ class ScriptBrowseNode( unohelper.Base, 
             elif name == "Editable" and ENABLE_EDIT_DIALOG:
                 ret = not self.provCtx.sfa.isReadOnly( self.uri )
 
-            log.isDebugLevel() and log.debug( "ScriptBrowseNode.getPropertyValue called for
" + name + ", returning " + str(ret) )
+            log.debug( "ScriptBrowseNode.getPropertyValue called for " + name + ", returning
" + str(ret) )
         except Exception,e:
             log.error( "ScriptBrowseNode.getPropertyValue error " + lastException2String())
             raise
 
         return ret
     def setPropertyValue( self, name, value ):
-        log.isDebugLevel() and log.debug( "ScriptBrowseNode.setPropertyValue called " + name
+ "=" +str(value ) )
+        log.debug( "ScriptBrowseNode.setPropertyValue called " + name + "=" +str(value )
)
     def getPropertySetInfo( self ):
-        log.isDebugLevel() and log.debug( "ScriptBrowseNode.getPropertySetInfo called " 
)
+        log.debug( "ScriptBrowseNode.getPropertySetInfo called "  )
         return None
 
     def getIntrospection( self ):
@@ -541,9 +541,9 @@ class ScriptBrowseNode( unohelper.Base, 
                 out.writeBytes( toWrite )
                 out.close()
                 self.provCtx.sfa.kill( copyUrl )
-#                log.isDebugLevel() and log.debug("Save is not implemented yet")
+#                log.debug("Save is not implemented yet")
 #                text = self.editor.getControl("EditorTextField").getText()
-#                log.isDebugLevel() and log.debug("Would save: " + text)
+#                log.debug("Would save: " + text)
         except Exception,e:
             # TODO: add an error box here !
             log.error( lastException2String() )
@@ -584,7 +584,7 @@ class FileBrowseNode( unohelper.Base, XB
                     ScriptBrowseNode(
                     self.provCtx, self.uri, self.name, i ))
             ret = tuple( scriptNodeList )
-            log.isDebugLevel() and log.debug( "returning " +str(len(ret)) + " ScriptChildNodes
on " + self.uri )
+            log.debug( "returning " +str(len(ret)) + " ScriptChildNodes on " + self.uri )
         except Exception, e:
             text = lastException2String()
             log.error( "Error while evaluating " + self.uri + ":" + text )
@@ -613,16 +613,16 @@ class DirBrowseNode( unohelper.Base, XBr
 
     def getChildNodes( self ):
         try:
-            log.isDebugLevel() and log.debug( "DirBrowseNode.getChildNodes called for " +
self.rootUrl )
+            log.debug( "DirBrowseNode.getChildNodes called for " + self.rootUrl )
             contents = self.provCtx.sfa.getFolderContents( self.rootUrl, True )
             browseNodeList = []
             for i in contents:
                 if i.endswith( ".py" ):
-                    log.isDebugLevel() and log.debug( "adding filenode " + i )
+                    log.debug( "adding filenode " + i )
                     browseNodeList.append(
                         FileBrowseNode( self.provCtx, i, i[i.rfind("/")+1:len(i)-3] ) )
                 elif self.provCtx.sfa.isFolder( i ) and not i.endswith("/pythonpath"):
-                    log.isDebugLevel() and log.debug( "adding DirBrowseNode " + i )
+                    log.debug( "adding DirBrowseNode " + i )
                     browseNodeList.append( DirBrowseNode( self.provCtx, i[i.rfind("/")+1:len(i)],i))
             return tuple( browseNodeList )
         except Exception, e:
@@ -713,18 +713,18 @@ class DummyInteractionHandler( unohelper
     def __init__( self ):
         pass
     def handle( self, event):
-        log.isDebugLevel() and log.debug( "pythonscript: DummyInteractionHandler.handle "
+ str( event ) )
+        log.debug( "pythonscript: DummyInteractionHandler.handle " + str( event ) )
 
 class DummyProgressHandler( unohelper.Base, XProgressHandler ):
     def __init__( self ):
         pass
 
     def push( self,status ):
-        log.isDebugLevel() and log.debug( "pythonscript: DummyProgressHandler.push " + str(
status ) )
+        log.debug( "pythonscript: DummyProgressHandler.push " + str( status ) )
     def update( self,status ):
-        log.isDebugLevel() and log.debug( "pythonscript: DummyProgressHandler.update " +
str( status ) )
+        log.debug( "pythonscript: DummyProgressHandler.update " + str( status ) )
     def pop( self ):
-        log.isDebugLevel() and log.debug( "pythonscript: DummyProgressHandler.push " + str(
event ) )
+        log.debug( "pythonscript: DummyProgressHandler.push " + str( event ) )
 
 class CommandEnvironment(unohelper.Base, XCommandEnvironment):
     def __init__( self ):
@@ -740,9 +740,9 @@ class CommandEnvironment(unohelper.Base,
 #    def __init__( self ):
 #        pass
 #    def modified( self, event ):
-#        log.isDebugLevel() and log.debug( "pythonscript: ModifyListener.modified " + str(
event ) )
+#        log.debug( "pythonscript: ModifyListener.modified " + str( event ) )
 #    def disposing( self, event ):
-#        log.isDebugLevel() and log.debug( "pythonscript: ModifyListener.disposing " + str(
event ) )
+#        log.debug( "pythonscript: ModifyListener.disposing " + str( event ) )
 
 def getModelFromDocUrl(ctx, url):
     """Get document model from document url."""
@@ -784,13 +784,13 @@ def getPackageName2PathMap( sfa, storage
     packageManager = packageManagerFactory.getPackageManager(
         mapStorageType2PackageContext(storageType))
 #    packageManager.addModifyListener( ModifyListener() )
-    log.isDebugLevel() and log.debug( "pythonscript: getPackageName2PathMap start getDeployedPackages"
)
+    log.debug( "pythonscript: getPackageName2PathMap start getDeployedPackages" )
     packages = packageManager.getDeployedPackages(
         packageManager.createAbortChannel(), CommandEnvironment( ) )
-    log.isDebugLevel() and log.debug( "pythonscript: getPackageName2PathMap end getDeployedPackages
(" + str(len(packages))+")" )
+    log.debug( "pythonscript: getPackageName2PathMap end getDeployedPackages (" + str(len(packages))+")"
)
 
     for i in packages:
-        log.isDebugLevel() and log.debug( "inspecting package " + i.Name + "("+i.Identifier.Value+")"
)
+        log.debug( "inspecting package " + i.Name + "("+i.Identifier.Value+")" )
         transientPathElement = penultimateElement( i.URL )
         j = expandUri( i.URL )
         pathes = getPathesFromPackage( j, sfa )
@@ -848,7 +848,7 @@ class PythonScript( unohelper.Base, XScr
         self.func = func
         self.mod = mod
     def invoke(self, args, out, outindex ):
-        log.isDebugLevel() and log.debug( "PythonScript.invoke " + str( args ) )
+        log.debug( "PythonScript.invoke " + str( args ) )
         try:
             ret = self.func( *args )
         except UnoException,e:
@@ -857,7 +857,7 @@ class PythonScript( unohelper.Base, XScr
             complete = "Error during invoking function " + \
                 str(self.func.__name__) + " in module " + \
                 self.mod.__file__ + " (" + text + ")"
-            log.isDebugLevel() and log.debug( complete )
+            log.debug( complete )
             # 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,
@@ -870,9 +870,9 @@ class PythonScript( unohelper.Base, XScr
             complete = "Error during invoking function " + \
                 str(self.func.__name__) + " in module " + \
                 self.mod.__file__ + " (" + text + ")"
-            log.isDebugLevel() and log.debug( complete )
+            log.debug( complete )
             raise RuntimeException( complete , self )
-        log.isDebugLevel() and log.debug( "PythonScript.invoke ret = " + str( ret ) )
+        log.debug( "PythonScript.invoke ret = " + str( ret ) )
         return ret, (), ()
 
 def expandUri(  uri ):
@@ -921,10 +921,10 @@ class PythonScriptProvider( unohelper.Ba
 #            urlHelper = ctx.ServiceManager.createInstanceWithArgumentsAndContext(
 #                "com.sun.star.script.provider.ScriptURIHelper", (LANGUAGENAME, storageType),
ctx)
             urlHelper = MyUriHelper( ctx, storageType )
-            log.isDebugLevel() and log.debug( "got urlHelper " + str( urlHelper ) )
+            log.debug( "got urlHelper " + str( urlHelper ) )
 
             rootUrl = expandUri( urlHelper.getRootStorageURI() )
-            log.isDebugLevel() and log.debug( storageType + " transformed to " + rootUrl
)
+            log.debug( storageType + " transformed to " + rootUrl )
 
             ucbService = "com.sun.star.ucb.SimpleFileAccess"
             sfa = ctx.ServiceManager.createInstanceWithContext( ucbService, ctx )
@@ -965,20 +965,20 @@ class PythonScriptProvider( unohelper.Ba
 
     def getScript( self, scriptUri ):
         try:
-            log.isDebugLevel() and log.debug( "getScript " + scriptUri + " invoked")
+            log.debug( "getScript " + scriptUri + " invoked")
 
             storageUri = self.provCtx.getStorageUrlFromPersistentUrl(
                 self.provCtx.uriHelper.getStorageURI(scriptUri) );
-            log.isDebugLevel() and log.debug( "getScript: storageUri = " + storageUri)
+            log.debug( "getScript: storageUri = " + storageUri)
             fileUri = storageUri[0:storageUri.find( "$" )]
             funcName = storageUri[storageUri.find( "$" )+1:len(storageUri)]
 
             mod = self.provCtx.getModuleByUrl( fileUri )
-            log.isDebugLevel() and log.debug( " got mod " + str(mod) )
+            log.debug( " got mod " + str(mod) )
 
             func = mod.__dict__[ funcName ]
 
-            log.isDebugLevel() and log.debug( "got func " + str( func ) )
+            log.debug( "got func " + str( func ) )
             return PythonScript( func, mod )
         except Exception, e:
             text = lastException2String()



Mime
View raw message