From 8466a159fe867280ab055f11afa79b9d4fc6be4c Mon Sep 17 00:00:00 2001 From: cermak Date: Tue, 14 Jan 2020 09:28:53 +0100 Subject: [PATCH] Compatibility with Python 3.4 This change allows compilation under python 3.4. In addition: - spec file added for pyinstaller with required hidden imports - changed default pathes for compiled exe file - added requirements for ppms under windows compilation Change-Id: I63d805a984d6a2c045df527303f46c8440994aad Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/22170 Reviewed-by: Enrico Faulhaber Reviewed-by: Markus Zolliker Reviewed-by: Petr Cermak Tested-by: JenkinsCodeReview Tested-by: Petr Cermak --- .gitignore | 3 +++ requirements.txt | 5 +++++ secop-server.spec | 38 ++++++++++++++++++++++++++++++++++++++ secop/__init__.py | 8 -------- secop/lib/__init__.py | 19 ++++++++++++++----- secop/params.py | 4 +++- 6 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 secop-server.spec diff --git a/.gitignore b/.gitignore index 883851b..e288e4a 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ doc/_build .cache .coverage ._* + +# pyinstaller +dist/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6c5c6f1..1a63e15 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,8 @@ psutil python-daemon >=2.0 # for zmq interface #pyzmq>=13.1.0 +#for ppms on windows +# don't forget to run +# 'python Scripts/pywin32_postinstall.py -install' +# from elevated prompt after install +#pywin32 diff --git a/secop-server.spec b/secop-server.spec new file mode 100644 index 0000000..706b678 --- /dev/null +++ b/secop-server.spec @@ -0,0 +1,38 @@ +# -*- mode: python ; coding: utf-8 -*- + +block_cipher = None + + +a = Analysis(['bin\\secop-server'], + pathex=['.'], + binaries=[], + datas=[], + hiddenimports=['secop.protocol', 'secop.protocol.dispatcher', 'secop.protocol.interface', 'secop.protocol.interface.tcp', + 'secop_psi.ppmssim', 'secop_psi.ppmswindows', 'secop_psi.ppms'], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + [], + exclude_binaries=True, + name='secop-server', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='secop-server') diff --git a/secop/__init__.py b/secop/__init__.py index fc38979..a120438 100644 --- a/secop/__init__.py +++ b/secop/__init__.py @@ -30,11 +30,3 @@ from secop.params import Parameter, Command, Override from secop.metaclass import Done from secop.iohandler import IOHandler, IOHandlerBase from secop.stringio import StringIO, HasIodev - - -try: - import sip - sip.setapi('QString', 2) - sip.setapi('QVariant', 2) -except ImportError: - pass diff --git a/secop/lib/__init__.py b/secop/lib/__init__.py index d29596d..a02ec9e 100644 --- a/secop/lib/__init__.py +++ b/secop/lib/__init__.py @@ -42,12 +42,21 @@ CONFIG = { 'logdir': os.path.join(repodir, 'log'), 'confdir': os.path.join(repodir, 'cfg'), 'basedir': repodir, -} if os.path.exists(os.path.join(repodir, '.git')) else { - 'piddir': '/var/run/secop', - 'logdir': '/var/log', - 'confdir': '/etc/secop', - 'basedir': repodir, } +if path.splitext(sys.executable)[1] == ".exe": + CONFIG = { + 'piddir': './', + 'logdir': './log', + 'confdir': './', + 'basedir': path.dirname(sys.executable), + } +elif not os.path.exists(os.path.join(repodir, '.git')): + CONFIG = { + 'piddir': '/var/run/secop', + 'logdir': '/var/log', + 'confdir': '/etc/secop', + 'basedir': repodir, + } unset_value = object() diff --git a/secop/params.py b/secop/params.py index 96911db..36b4955 100644 --- a/secop/params.py +++ b/secop/params.py @@ -162,7 +162,9 @@ class Parameter(Accessible): def getProperties(self): """get also properties of datatype""" - return {**super().getProperties(), **self.datatype.getProperties()} + superProp = super().getProperties().copy() + superProp.update(self.datatype.getProperties()) + return superProp def setProperty(self, key, value): """set also properties of datatype"""