This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch python-editing-embedding
in repository https://gitbox.apache.org/repos/asf/openoffice.git
The following commit(s) were added to refs/heads/python-editing-embedding by
this push:
new 1a9bb40f52 Forget Python modules from the cache after they are saved,
so they get reloaded in the future. This is necessary as getModuleByUrl()'s
self.sfa.getDateTimeModified() returns timestamps with all zeroes for documents
(== ZIP files), breaking the test for whether the embedded Python file has been
changed. Also even if it worked, the minimum granularity for timestamps in ZIP
files is 2 seconds, which isn't good enough.
1a9bb40f52 is described below
commit 1a9bb40f526ecd221fae80ff3d03543e39cd06fd
Author: Damjan Jovanovic <[email protected]>
AuthorDate: Wed Apr 29 05:31:07 2026 +0200
Forget Python modules from the cache after they are saved, so they
get reloaded in the future. This is necessary as getModuleByUrl()'s
self.sfa.getDateTimeModified() returns timestamps with all zeroes
for documents (== ZIP files), breaking the test for whether the
embedded Python file has been changed. Also even if it worked, the
minimum granularity for timestamps in ZIP files is 2 seconds, which
isn't good enough.
Patch by: me
---
main/scripting/source/pyprov/pythonscript.py | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/main/scripting/source/pyprov/pythonscript.py
b/main/scripting/source/pyprov/pythonscript.py
index 2594eeed2e..9f4fb56e86 100644
--- a/main/scripting/source/pyprov/pythonscript.py
+++ b/main/scripting/source/pyprov/pythonscript.py
@@ -502,6 +502,14 @@ class ProviderContext:
log.debug( "mapped " + url + " to " + str( entry.module ) )
return entry.module
+ # Forgets a stale module so a fresh copy can be loaded in the future.
+ # This is necessary because getModuleByUrl()'s
self.sfa.getDateTimeModified()
+ # doesn't always work, eg. for embedded scripts it always returns
timestamps
+ # with all zeroes, and even if it worked, the smallest granularity for ZIP
file
+ # timestamps is 2 seconds, which isn't good enough.
+ def removeModuleByUrl( self, url ):
+ del self.modules[ url ]
+
def createEditorDialog( ctx ):
smgr = ctx.ServiceManager
@@ -671,6 +679,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode,
XPropertySet, XInvocation,
self.provCtx.sfa.move( self.uri(), copyUrl )
log.debug( "Saving Python macro to URI " + self.uri() )
self.provCtx.sfa.writeFile( self.uri(), BytesInputStream(
toWrite.value ) )
+ self.provCtx.removeModuleByUrl( self.uri() )
self.provCtx.sfa.kill( copyUrl )
except Exception as e:
# TODO: add an error box here !
@@ -834,6 +843,7 @@ class FileBrowseNode( unohelper.Base, XBrowseNode,
XPropertySet, XInvocation, XA
self.provCtx.sfa.move( self.uri(), copyUrl )
log.debug( "Saving Python macro to URI " + self.uri() )
self.provCtx.sfa.writeFile( self.uri(), BytesInputStream(
toWrite.value ) )
+ self.provCtx.removeModuleByUrl( self.uri() )
self.provCtx.sfa.kill( copyUrl )
except Exception as e:
# TODO: add an error box here !