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..7db12da 100644 --- a/Makefile +++ b/Makefile @@ -4,40 +4,74 @@ MAKEFLAGS = --no-print-directory --no-builtin-rules # Variables PACKAGE = revpipyload +APP_NAME = RevPiPyLoad +APP_IDENT = org.revpimodio.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 -all: build +# If virtualenv exists, use it. If not, use PATH to find commands +SYSTEM_PYTHON = python3 +PYTHON = $(or $(wildcard $(VENV_PATH)/bin/python), $(SYSTEM_PYTHON)) + +APP_VERSION = $(shell "$(PYTHON)" src/$(PACKAGE) --version | cut -d ' ' -f 2) + +all: test build .PHONY: all ## Environment +venv-info: + @echo Environment for $(APP_NAME) $(APP_VERSION) + @echo Using path: "$(VENV_PATH)" + exit 0 + venv: - $(SYSTEM_PYTHON) -m venv venv - source venv/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 +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 +distclean: clean + # Virtual environment + rm -rf "$(VENV_PATH)" -.PHONY: clean clean-all +.PHONY: clean distclean 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" 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" diff --git a/src/revpipyload/revpipyload.py b/src/revpipyload/revpipyload.py index 7d258a7..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") @@ -1294,8 +1296,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: @@ -1358,11 +1361,39 @@ class RevPiPyLoad: "".format(self.xmlrpcacl.filename) ) - # RevPiPyLoad neu konfigurieren - self.evt_loadconfig.set() + if loadnow: + # RevPiPyLoad neu konfigurieren + self.evt_loadconfig.set() 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.