From a5b728dc7c68fe707b1cbf7a225c357502458a24 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Thu, 26 Oct 2023 12:58:28 +0200 Subject: [PATCH 1/6] chore: Release 0.11.0rc1 Signed-off-by: Sven Sager --- src/revpipyload/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/revpipyload/__init__.py b/src/revpipyload/__init__.py index 6ca85db..ff08a40 100644 --- a/src/revpipyload/__init__.py +++ b/src/revpipyload/__init__.py @@ -4,4 +4,4 @@ __author__ = "Sven Sager" __copyright__ = "Copyright (C) 2023 Sven Sager" __license__ = "GPLv2" __package__ = "revpipyload" -__version__ = "0.10.0" +__version__ = "0.11.0rc1" From ee32621dcf4434319fa5eb660a3295fd261f3f18 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Tue, 29 Aug 2023 10:39:01 +0200 Subject: [PATCH 2/6] build: Add environment variable to set alternative venv path --- .idea/misc.xml | 2 +- .idea/revpipyload.iml | 2 +- .idea/vcs.xml | 2 ++ Makefile | 25 ++++++++++++++++++------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8c91e35..a4920b4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + diff --git a/.idea/revpipyload.iml b/.idea/revpipyload.iml index e32621b..9d47fbc 100644 --- a/.idea/revpipyload.iml +++ b/.idea/revpipyload.iml @@ -5,7 +5,7 @@ - + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 029a1a8..2e1637c 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -3,6 +3,8 @@ + + diff --git a/Makefile b/Makefile index 25345b1..be32e00 100644 --- a/Makefile +++ b/Makefile @@ -5,23 +5,34 @@ MAKEFLAGS = --no-print-directory --no-builtin-rules # Variables PACKAGE = revpipyload -# If virtualenv exists, use it. If not, use PATH to find, except python3 -SYSTEM_PYTHON = /usr/bin/python3 -PYTHON = $(or $(wildcard venv/bin/python), $(SYSTEM_PYTHON)) +# Set path to create the virtual environment with package name +ifdef PYTHON3_VENV +VENV_PATH = $(PYTHON3_VENV)/$(PACKAGE) +else +VENV_PATH = venv +endif + +# If virtualenv exists, use it. If not, use PATH to find commands +SYSTEM_PYTHON = python3 +PYTHON = $(or $(wildcard $(VENV_PATH)/bin/python), $(SYSTEM_PYTHON)) all: build .PHONY: all ## Environment +venv-info: + echo Using path: "$(VENV_PATH)" + exit 0 + venv: - $(SYSTEM_PYTHON) -m venv venv - source venv/bin/activate && \ + $(SYSTEM_PYTHON) -m venv "$(VENV_PATH)" + source $(VENV_PATH)/bin/activate && \ python3 -m pip install --upgrade pip && \ python3 -m pip install -r requirements.txt exit 0 -.PHONY: venv +.PHONY: venv-info venv ## Build, install build: @@ -38,6 +49,6 @@ clean: rm -rf build dist src/*.egg-info *.spec clean-all: clean - rm -R venv + rm -R $(VENV_PATH) .PHONY: clean clean-all From 7bc1adcc2a32d66baabd514e57cd0610c3a98558 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Sat, 16 Sep 2023 12:35:15 +0200 Subject: [PATCH 3/6] build: Fix Makefile targets to match GNU coding standards - Rename target clean-all to distclean - Add uninstall target - Install target has to run tests Signed-off-by: Sven Sager --- Makefile | 51 +++++++++++++++++++++++++++---------- src/revpipyload/__main__.py | 15 +++-------- src/revpipyload/proginit.py | 7 +++++ 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index be32e00..7db12da 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ MAKEFLAGS = --no-print-directory --no-builtin-rules # Variables PACKAGE = revpipyload +APP_NAME = RevPiPyLoad +APP_IDENT = org.revpimodio.revpipyload # Set path to create the virtual environment with package name ifdef PYTHON3_VENV @@ -16,39 +18,60 @@ endif SYSTEM_PYTHON = python3 PYTHON = $(or $(wildcard $(VENV_PATH)/bin/python), $(SYSTEM_PYTHON)) -all: build +APP_VERSION = $(shell "$(PYTHON)" src/$(PACKAGE) --version | cut -d ' ' -f 2) + +all: test build .PHONY: all ## Environment venv-info: - echo Using path: "$(VENV_PATH)" + @echo Environment for $(APP_NAME) $(APP_VERSION) + @echo Using path: "$(VENV_PATH)" exit 0 venv: - $(SYSTEM_PYTHON) -m venv "$(VENV_PATH)" - source $(VENV_PATH)/bin/activate && \ + # Start with empty environment + "$(SYSTEM_PYTHON)" -m venv "$(VENV_PATH)" + source "$(VENV_PATH)/bin/activate" && \ python3 -m pip install --upgrade pip && \ python3 -m pip install -r requirements.txt exit 0 -.PHONY: venv-info venv +venv-ssp: + # Include system installed site-packages and add just missing modules + "$(SYSTEM_PYTHON)" -m venv --system-site-packages "$(VENV_PATH)" + source "$(VENV_PATH)/bin/activate" && \ + python3 -m pip install --upgrade pip && \ + python3 -m pip install -r requirements.txt + exit 0 -## Build, install +.PHONY: venv-info venv venv-ssp + +## Build steps build: - $(PYTHON) -m setup sdist - $(PYTHON) -m setup bdist_wheel + "$(PYTHON)" -m setup sdist + "$(PYTHON)" -m setup bdist_wheel install: build - $(PYTHON) -m pip install dist/$(PACKAGE)-*.whl + "$(PYTHON)" -m pip install dist/$(PACKAGE)-$(APP_VERSION)-*.whl -.PHONY: build install +uninstall: + "$(PYTHON)" -m pip uninstall --yes $(PACKAGE) + +.PHONY: test build install uninstall ## Clean clean: - rm -rf build dist src/*.egg-info *.spec + # PyTest caches + rm -rf .pytest_cache + # Build artifacts + rm -rf build dist src/*.egg-info + # PyInstaller created files + rm -rf *.spec -clean-all: clean - rm -R $(VENV_PATH) +distclean: clean + # Virtual environment + rm -rf "$(VENV_PATH)" -.PHONY: clean clean-all +.PHONY: clean distclean diff --git a/src/revpipyload/__main__.py b/src/revpipyload/__main__.py index 6c040c1..f7e6e08 100644 --- a/src/revpipyload/__main__.py +++ b/src/revpipyload/__main__.py @@ -17,15 +17,8 @@ if __package__ == "": if __name__ == "__main__": import sys - if len(sys.argv) == 2 and "--version" in sys.argv: - # Catch --version, if this is the only argument (sys.argv[0] is always the script name) - from revpipyload import __version__ + # Use absolut import in the __main__ module + from revpipyload.revpipyload import main - print(__version__) - sys.exit(0) - - else: - from revpipyload.revpipyload import main - - # Run the main application of this package - sys.exit(main()) + # Run the main application of this package + sys.exit(main()) diff --git a/src/revpipyload/proginit.py b/src/revpipyload/proginit.py index 79cebe0..d508627 100644 --- a/src/revpipyload/proginit.py +++ b/src/revpipyload/proginit.py @@ -10,6 +10,8 @@ import sys from argparse import ArgumentParser from configparser import ConfigParser +from . import __version__ + conf = ConfigParser() forked = False globalconffile = None @@ -42,6 +44,11 @@ def configure(): parser = ArgumentParser( description="RevolutionPi Python Loader" ) + parser.add_argument( + "--version", + action="version", + version="%(prog)s {0}".format(__version__) + ) parser.add_argument( "-d", "--daemon", action="store_true", dest="daemon", help="Run program as a daemon in background" From 87effde838fe41fec67239449c39c94c58903a47 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Thu, 26 Oct 2023 07:38:04 +0200 Subject: [PATCH 4/6] fix: Fixes the error that setconfig always reloads the settings The parameter 'loadnow' has not been processed since commit 3222790d and the settings have always been applied immediately. Refs: 3222790d Signed-off-by: Sven Sager --- src/revpipyload/revpipyload.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/revpipyload/revpipyload.py b/src/revpipyload/revpipyload.py index 7d258a7..cc8c00b 100644 --- a/src/revpipyload/revpipyload.py +++ b/src/revpipyload/revpipyload.py @@ -1358,8 +1358,9 @@ class RevPiPyLoad: "".format(self.xmlrpcacl.filename) ) - # RevPiPyLoad neu konfigurieren - self.evt_loadconfig.set() + if loadnow: + # RevPiPyLoad neu konfigurieren + self.evt_loadconfig.set() return True From 5b4c799c985564da85561cafc9b8161164e2ff1b Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Thu, 26 Oct 2023 07:41:51 +0200 Subject: [PATCH 5/6] fix: Settings name translation has to check the existence of key In the 'xml_setconfig' function, the names of the passed dictionary are translated into new names. However, there is no obligation to hand over all fields in the setting dict. This bugfix checks whether the keys exist before translating. Refs: 6d56c667 Signed-off-by: Sven Sager --- src/revpipyload/revpipyload.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/revpipyload/revpipyload.py b/src/revpipyload/revpipyload.py index cc8c00b..cfe77d1 100644 --- a/src/revpipyload/revpipyload.py +++ b/src/revpipyload/revpipyload.py @@ -1294,8 +1294,9 @@ class RevPiPyLoad: ("plcslaveport", "plcserverport"), ("plcslavewatchdog", "plcserverwatchdog"), ): - dc[key_to] = dc[key_from] - del dc[key_from] + if key_from in dc: + dc[key_to] = dc[key_from] + del dc[key_from] # Werte übernehmen, die eine Definition in key haben (andere nicht) for sektion in keys: From 16102a2aa375483a17e95e05712ef153cee2b302 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Thu, 26 Oct 2023 12:30:34 +0200 Subject: [PATCH 6/6] feat: New XML-RPC function 'set_plcprogram' With the new XML-RPC function, a new PLC program can be passed, which is loaded directly and saved in the configuration file. Signed-off-by: Sven Sager --- src/revpipyload/revpipyload.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/revpipyload/revpipyload.py b/src/revpipyload/revpipyload.py index cfe77d1..87aac87 100644 --- a/src/revpipyload/revpipyload.py +++ b/src/revpipyload/revpipyload.py @@ -477,6 +477,8 @@ class RevPiPyLoad: # XML Modus 4 Einstellungen ändern self.xsrv.register_function( 4, self.xml_setconfig, "set_config") + self.xsrv.register_function( + 4, self.xml_setplcprogram, "set_plcprogram") self.xsrv.register_function( 4, self.xml_setpictoryrsc, "set_pictoryrsc") @@ -1365,6 +1367,33 @@ class RevPiPyLoad: return True + def xml_setplcprogram(self, plcprogram: str) -> int: + """ + Set new plc program, without restart services. + + :returns: 0 Erfolgreich + -1 Programm lauft noch + -2 Datei nicht gefunden + """ + if type(plcprogram) is not str: + raise TypeError("The given plc program must be ") + if not plcprogram: + raise ValueError("Empty string not allowed for plc program") + + stop_code = self.xml_plcstop() + + # Set the new plc program setting to activ configuration + self.plcprogram = plcprogram + + # Save the new value to config file without reload + self.xml_setconfig({"plcprogram": plcprogram}, False) + + # Start the program, if it was running before change + if stop_code > -1: + return self.xml_plcstart() + + return 0 + def xml_setpictoryrsc(self, filebytes, reset=False): """Schreibt die config.rsc Datei von piCotry.