Apache OpenOffice (AOO) Bugzilla – Issue 127302
Python script provider does not reload modified embedded scripts
Last modified: 2017-01-30 14:20:52 UTC
The python script provider (pythoncript.py) checks if a module needs to be reloaded by comparing file date-time. This is done using the method "getDateTimeModified" of service css.ucb.SimpleFileAccess. But this works only for external scripts : when executed on embedded scripts, "getDateTimeModified" always returns a null DateTime struct (let's assume this is not a bug) and therefore these scripts are never reloaded when modified. For example, with the following instruction : # sfa = instance of css.ucb.SimpleFileAccess sfa.copy("/user/pyscript.py", "vnd.sun.star.tdoc:/1/Scripts/python/pyscript.py") the embedded pyscript.py is updated and correctly loaded with any *new* instance of the script provider. However, the provider instance attached to the document will keep his reference to the first loaded version of the py file until next reopening. In other words, when an embedded script is bound to some control or toolbar element and executed once, it will never be reloaded even if modified. I'm not totally sure but it seems that, instead of using "getDateTimeModified" in this particular case, it would be at least possible to rely on the method "isModified" of the document storage to track changes. If this is correct, a kind of fix could look like this : [old code, starting at line 426 of pythonscript.py] def getModuleByUrl( self, url ): entry = self.modules.get(url) load = True lastRead = self.sfa.getDateTimeModified( url ) if entry: if hasChanged( entry.lastRead, lastRead ): log.debug( "file " + url + " has changed, reloading" ) else: load = False if load: [...] [new code] def getModuleByUrl( self, url ): entry = self.modules.get(url) load = True lastRead = self.sfa.getDateTimeModified( url ) if entry: if url.startswith( "file:" ): if hasChanged( entry.lastRead, lastRead ): log.debug( "file " + url + " has changed, reloading" ) else: load = False else: storage = self.scriptContext.doc.getDocumentStorage() load = storage.isModified() storage.commit() if load: [...] Thanks in advance.