summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2007-10-11 10:52:00 +0000
committerKurt Zenker <kz@openoffice.org>2007-10-11 10:52:00 +0000
commit160fe6faae6608ff7b3cb05f0b5d94cffeca2682 (patch)
tree236db9c35cb6e7960c829ccc7fb5cedffd88829f /pyuno
parent17349ce69c49966c920f815dce333754b43b2b6c (diff)
INTEGRATION: CWS pyunofixes4 (1.4.66); FILE MERGED
2007/07/30 19:43:44 jbu 1.4.66.1: adding pythonpath import functionality, fixed a gc deadlock, fixed some minor issues
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/source/loader/pythonloader.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/pyuno/source/loader/pythonloader.py b/pyuno/source/loader/pythonloader.py
index 24ad32faa..f2391ad01 100644
--- a/pyuno/source/loader/pythonloader.py
+++ b/pyuno/source/loader/pythonloader.py
@@ -4,9 +4,9 @@
#
# $RCSfile: pythonloader.py,v $
#
-# $Revision: 1.4 $
+# $Revision: 1.5 $
#
-# last change: $Author: rt $ $Date: 2005-09-08 16:50:23 $
+# last change: $Author: kz $ $Date: 2007-10-11 11:52:00 $
#
# The Contents of this file are made available subject to
# the terms of GNU Lesser General Public License Version 2.1.
@@ -34,6 +34,7 @@
#*************************************************************************
import uno
import unohelper
+import sys
import imp
import os
from com.sun.star.uno import Exception,RuntimeException
@@ -49,10 +50,24 @@ g_implementationName = "org.openoffice.comp.pyuno.Loader" # referenced by the na
def splitUrl( url ):
nColon = url.find( ":" )
if -1 == nColon:
- raise RuntimeException( "PythonLoader: No protocol in url " + url )
+ raise RuntimeException( "PythonLoader: No protocol in url " + url, None )
return url[0:nColon], url[nColon+1:len(url)]
g_loadedComponents = {}
+def checkForPythonPathBesideComponent( url ):
+ path = unohelper.fileUrlToSystemPath( url+"/pythonpath.zip" );
+ if DEBUG == 1:
+ print "checking for existence of " + path
+ if 1 == os.access( path, os.F_OK) and not path in sys.path:
+ if DEBUG == 1:
+ print "adding " + path + " to sys.path"
+ sys.path.append( path )
+
+ path = unohelper.fileUrlToSystemPath( url+"/pythonpath" );
+ if 1 == os.access( path, os.F_OK) and not path in sys.path:
+ if DEBUG == 1:
+ print "adding " + path + " to sys.path"
+ sys.path.append( path )
class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
def __init__(self, ctx ):
@@ -82,12 +97,20 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
if not mod:
mod = imp.new_module("uno_component")
+ # check for pythonpath.zip beside .py files
+ checkForPythonPathBesideComponent( url[0:url.rfind('/')] )
+
# read the file
- fileHandle = file( unohelper.fileUrlToSystemPath( url ) )
- src = fileHandle.read()
-
- # execute the module
- exec src in mod.__dict__
+ filename = unohelper.fileUrlToSystemPath( url )
+ fileHandle = file( filename )
+ src = fileHandle.read().replace("\r","")
+ if not src.endswith( "\n" ):
+ src = src + "\n"
+
+ # compile and execute the module
+ codeobject = compile( src, filename, "exec" )
+ exec codeobject in mod.__dict__
+ mod.__file__ = filename
g_loadedComponents[url] = mod
return mod
elif "vnd.openoffice.pymodule" == protocol: