[Libreoffice-commits] core.git: wizards/source

Jean-Pierre Ledure (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 1 09:05:43 UTC 2021


 wizards/source/scriptforge/SF_Root.xba                 |    2 ++
 wizards/source/scriptforge/SF_Session.xba              |    7 +++++++
 wizards/source/scriptforge/python/ScriptForgeHelper.py |    1 +
 wizards/source/scriptforge/python/scriptforge.py       |    5 +++++
 4 files changed, 15 insertions(+)

New commits:
commit 28ee6bc8cf9548a6c24e68e5804077a96605a1f2
Author:     Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Wed Jun 30 17:07:43 2021 +0200
Commit:     Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Thu Jul 1 11:05:09 2021 +0200

    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 at ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>

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:


More information about the Libreoffice-commits mailing list