https://bugs.documentfoundation.org/show_bug.cgi?id=105609

            Bug ID: 105609
           Summary: Python script provider does not reload modified
                    embedded scripts
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: libreoffice-bugs@lists.freedesktop.org
          Reporter: jeanmarczam...@gmail.com

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
        if entry:
            if url.startswith( "file:" ):
                lastRead = self.sfa.getDateTimeModified( url )
                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.

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
Libreoffice-bugs@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to