summaryrefslogtreecommitdiff
path: root/pyuno/source
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2011-12-05 13:04:05 +0000
committerMichael Meeks <michael.meeks@suse.com>2011-12-05 20:53:24 +0000
commit41b8bad143c06bc5419783b9f3cf5685aa3eea63 (patch)
tree440af2f411acfd9bbf43c6d3f33da0a94ae3b4d0 /pyuno/source
parentfb7f82382bd317dd12913a6d7a3a5e4be6a6671c (diff)
wizards: completely work python wizard packaging and registration
Also improve exception handling and error printing in pythonloader Allow registration of explicit .py components - the only method that works
Diffstat (limited to 'pyuno/source')
-rw-r--r--pyuno/source/loader/pythonloader.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py
index ad72cca86266..5675a0c9596c 100644
--- a/pyuno/source/loader/pythonloader.py
+++ b/pyuno/source/loader/pythonloader.py
@@ -35,7 +35,7 @@ from com.sun.star.loader import XImplementationLoader
from com.sun.star.lang import XServiceInfo
MODULE_PROTOCOL = "vnd.openoffice.pymodule:"
-DEBUG = 0
+DEBUG = 1
g_supportedServices = "com.sun.star.loader.Python", # referenced by the native C++ loader !
g_implementationName = "org.openoffice.comp.pyuno.Loader" # referenced by the native C++ loader !
@@ -98,6 +98,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
# read the file
filename = unohelper.fileUrlToSystemPath( url )
+
fileHandle = file( filename )
src = fileHandle.read().replace("\r","")
if not src.endswith( "\n" ):
@@ -110,11 +111,23 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
g_loadedComponents[url] = mod
return mod
elif "vnd.openoffice.pymodule" == protocol:
- return __import__( dependent )
+ print ("here")
+ nSlash = dependent.rfind('/')
+ if -1 != nSlash:
+ path = unohelper.fileUrlToSystemPath( dependent[0:nSlash] )
+ dependent = dependent[nSlash+1:len(dependent)]
+ if not path in sys.path:
+ sys.path.append( path )
+ var = __import__( dependent )
+ return var
else:
+ if DEBUG:
+ print("Unknown protocol '" + protocol + "'");
raise RuntimeException( "PythonLoader: Unknown protocol " +
protocol + " in url " +url, self )
- except ImportError as e:
+ except Exception as e:
+ if DEBUG:
+ print ("Python import error " + str(e) + " args " + str(e.args));
raise RuntimeException( "Couldn't load " + url + " for reason " + str(e), None )
return None
@@ -124,6 +137,9 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
mod = self.getModuleFromUrl( locationUrl )
implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
+ print ("dump stuff")
+ if DEBUG:
+ print ("Fetched ImplHelper as " + str(implHelper))
if implHelper == None:
return mod.getComponentFactory( implementationName, self.ctx.ServiceManager, regKey )
else: