diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2021-06-30 17:07:43 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2021-07-01 11:05:09 +0200 |
commit | 28ee6bc8cf9548a6c24e68e5804077a96605a1f2 (patch) | |
tree | e3772a952f331ff2437524bf2ee669415b9cfb41 | |
parent | f63c56f87294d87275b409f6b39b7fcdc0b2be92 (diff) |
ScriptForge - Backdoor to alternate Python helper script
While developing a new version of
ScriptForgeHelper.py
the dev should be sure to invoke the new version
instead of the standard version shipped with its
LO release.
This can be done now by setting
- in Python a specific ScriptForge class property
ScriptForge.pythonhelpermodule2 = 'user#QA/ScriptForgeHelper.py'
- in Basic a specific property of the root class
_SF_.PythonHelper2 = "QA/ScriptForgeHelper.py"
both in the test script
Testing a new version of scriptforge.py can be configured
entirely from the test script by inserting next statements
import sys
sys.path.reverse()
sys.path.append('/home/jean-pierre/.config/libreoffice/4/user/Scripts/python/QA')
sys.path.reverse()
Change-Id: Iab6db518932e9dde9030b7e5bbe00a50dee31840
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118171
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
-rw-r--r-- | wizards/source/scriptforge/SF_Root.xba | 2 | ||||
-rw-r--r-- | wizards/source/scriptforge/SF_Session.xba | 7 | ||||
-rw-r--r-- | wizards/source/scriptforge/python/ScriptForgeHelper.py | 1 | ||||
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 5 |
4 files changed, 15 insertions, 0 deletions
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba index 6e89920a3c34..f435bcec6f1f 100644 --- a/wizards/source/scriptforge/SF_Root.xba +++ b/wizards/source/scriptforge/SF_Root.xba @@ -77,6 +77,7 @@ Private TreeDataModel As Object ' com.sun.star.awt.tree.MutableTreeDataMod ' Specific persistent services objects or properties Private FileSystemNaming As String ' If "SYS", file and folder naming is based on operating system notation Private PythonHelper As String ' File name of Python helper functions (stored in $(inst)/share/Scripts/python) +Private PythonHelper2 As String ' Alternate Python helper file name for test purposes Private Interface As Object ' ScriptForge own L10N service Private OSName As String ' WIN, LINUX, MACOS Private SFDialogs As Variant ' Persistent storage for the SFDialogs library @@ -127,6 +128,7 @@ Private Sub Class_Initialize() Set Introspection = Nothing FileSystemNaming = "ANY" PythonHelper = "ScriptForgeHelper.py" + PythonHelper2 = "" Set Interface = Nothing Set BrowseNodeFactory = Nothing Set DatabaseContext = Nothing diff --git a/wizards/source/scriptforge/SF_Session.xba b/wizards/source/scriptforge/SF_Session.xba index 837c26b2a048..63fd4c57bf0a 100644 --- a/wizards/source/scriptforge/SF_Session.xba +++ b/wizards/source/scriptforge/SF_Session.xba @@ -291,6 +291,13 @@ Try: If VarType(vArg) = V_DATE Then pvArgs(i) = SF_Utils._CDateToIso(vArg) Next i + ' Intercept alternate Python helpers file when relevant + With _SF_ + If SF_String.StartsWith(Script, .PythonHelper) And Len(.PythonHelper2) > 0 Then + Scope = SCRIPTISPERSONAL + Script = .PythonHelper2 & Mid(Script, Len(.PythonHelper) + 1) + End If + End With ' Find script Set oScript = SF_Session._GetScript("Python", Scope, Script) diff --git a/wizards/source/scriptforge/python/ScriptForgeHelper.py b/wizards/source/scriptforge/python/ScriptForgeHelper.py index aec9311a3f3f..12fbaa337ebe 100644 --- a/wizards/source/scriptforge/python/ScriptForgeHelper.py +++ b/wizards/source/scriptforge/python/ScriptForgeHelper.py @@ -283,6 +283,7 @@ if __name__ == "__main__": print(_SF_Platform('OSRelease')) print(_SF_Platform('OSVersion')) print(_SF_Platform('Processor')) + print(_SF_Platform('PythonVersion')) # print(hashlib.algorithms_guaranteed) print(_SF_FileSystem__HashFile('/opt/libreoffice6.4/program/libbootstraplo.so', 'md5')) diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 33b98fc491f8..0f16613d618f 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -224,6 +224,11 @@ class ScriptForge(object, metaclass = _Singleton): if '.py$' in script.lower(): # Python if len(scope) == 0: scope = 'share' # Default for Python + # Provide an alternate helper script depending on test context + if script.startswith(cls.pythonhelpermodule) and hasattr(cls, 'pythonhelpermodule2'): + script = cls.pythonhelpermodule2 + script[len(cls.pythonhelpermodule):] + if '#' in script: + scope, script = script.split('#') uri = 'vnd.sun.star.script:{0}?language=Python&location={1}'.format(script, scope) else: # Basic if len(scope) == 0: |