Issue 127302 - Python script provider does not reload modified embedded scripts
Summary: Python script provider does not reload modified embedded scripts
Status: UNCONFIRMED
Alias: None
Product: General
Classification: Code
Component: scripting (show other issues)
Version: 4.1.2
Hardware: All All
: P5 (lowest) Normal (vote)
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-30 14:20 UTC by spyre
Modified: 2017-01-30 14:20 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description spyre 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.