summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authorOliver Bolte <obo@openoffice.org>2006-03-22 09:46:30 +0000
committerOliver Bolte <obo@openoffice.org>2006-03-22 09:46:30 +0000
commit801a501e4b6fb79f76d355d20ca92605a26c8e6c (patch)
treed4fe70a3d3c2cd2a37f506003086ca2c681a9064 /scripting
parent217271dea34a12be38fb2c1d077adb50c7632a92 (diff)
INTEGRATION: CWS pyunofixes2 (1.4.34); FILE MERGED
2006/01/11 22:14:05 jbu 1.4.34.2: #i54155# ensuring now, that a linefeed is appended to the script when necessary, some additional code cleanup 2006/01/07 20:07:23 jbu 1.4.34.1: #i54157# added a flush in log function (needed on win32)
Diffstat (limited to 'scripting')
-rw-r--r--scripting/source/pyprov/pythonscript.py55
1 files changed, 32 insertions, 23 deletions
diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py
index a03326c4f647..bc871fa516f0 100644
--- a/scripting/source/pyprov/pythonscript.py
+++ b/scripting/source/pyprov/pythonscript.py
@@ -62,6 +62,7 @@ class Logger(LogLevel):
"] " +
msg +
"\n" )
+ self.target.flush()
log = Logger( getLogTarget() )
@@ -119,6 +120,11 @@ def hasChanged( oldDate, newDate ):
newDate.Seconds > oldDate.Seconds or \
newDate.HundredthSeconds > oldDate.HundredthSeconds
+def ensureCodeEndsWithLinefeed( code ):
+ if not code.endswith( "\n" ):
+ code = code + "\n"
+ return code
+
class ScriptContext(unohelper.Base):
def __init__( self, ctx, doc ):
self.ctx = ctx
@@ -140,31 +146,31 @@ class ScriptContext(unohelper.Base):
# does not fit together with script
# engine lifetime management
#----------------------------------
-g_scriptContext = ScriptContext( uno.getComponentContext(), None )
-g_modules = {}
-def getModuleByUrl( url, sfa ):
- entry = g_modules.get(url)
- load = True
- lastRead = sfa.getDateTimeModified( url )
- if entry:
- if hasChanged( entry.lastRead, lastRead ):
- log.isDebugLevel() and log.debug("file " + url + " has changed, reloading")
- else:
- load = False
-
- if load:
- log.isDebugLevel() and log.debug( "opening >" + url + "<" )
-
- code = readTextFromStream( sfa.openFileRead( url ) )
+#g_scriptContext = ScriptContext( uno.getComponentContext(), None )
+#g_modules = {}
+#def getModuleByUrl( url, sfa ):
+# entry = g_modules.get(url)
+# load = True
+# lastRead = sfa.getDateTimeModified( url )
+# if entry:
+# if hasChanged( entry.lastRead, lastRead ):
+# log.isDebugLevel() and log.debug("file " + url + " has changed, reloading")
+# else:
+# load = False
+#
+# if load:
+# log.isDebugLevel() and log.debug( "opening >" + url + "<" )
+#
+# code = readTextFromStream( sfa.openFileRead( url ) )
# execute the module
- entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") )
- entry.module.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = g_scriptContext
- 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 ) )
- return entry.module
+# entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") )
+# entry.module.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = g_scriptContext
+# 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 ) )
+# return entry.module
class ProviderContext:
def __init__( self, storageType, sfa, uriHelper, scriptContext ):
@@ -248,6 +254,7 @@ class ProviderContext:
log.isDebugLevel() and log.debug( "opening >" + url + "<" )
code = readTextFromStream( self.sfa.openFileRead( url ) )
+ code = ensureCodeEndsWithLinefeed( code )
# execute the module
entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") )
@@ -319,6 +326,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
"ScriptBindingLibrary.MacroEditor?location=application")
code = readTextFromStream(self.provCtx.sfa.openFileRead(self.uri))
+ code = ensureCodeEndsWithLinefeed( code )
self.editor.getControl("EditorTextField").setText(code)
self.editor.getControl("RunButton").setActionCommand("Run")
@@ -334,6 +342,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
try:
if event.ActionCommand == "Run":
code = self.editor.getControl("EditorTextField").getText()
+ code = ensureCodeEndsWithLinefeed( code )
mod = imp.new_module("ooo_script_framework")
mod.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = self.provCtx.scriptContext
exec code in mod.__dict__