From 2b257183d97d8a7ea9c7d865d7dd1a6e079b82a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Wed, 9 Sep 2020 10:56:11 +0200 Subject: [PATCH] #940: Recover files to build OGAgent for Windows Python 2-compatible. --- src/opengnsys/windows/OGAgentService.py | 2 +- src/opengnsys/windows/__init__.py | 2 +- src/opengnsys/windows/log.py | 2 +- src/opengnsys/windows/operations.py | 12 ++--- windows/py2exe-wine-linux.sh | 67 +++++++++++++++++++++++++ windows/pyinstaller-wine.sh | 56 --------------------- 6 files changed, 76 insertions(+), 65 deletions(-) create mode 100755 windows/py2exe-wine-linux.sh delete mode 100755 windows/pyinstaller-wine.sh diff --git a/src/opengnsys/windows/OGAgentService.py b/src/opengnsys/windows/OGAgentService.py index 857b2cc..71716d7 100644 --- a/src/opengnsys/windows/OGAgentService.py +++ b/src/opengnsys/windows/OGAgentService.py @@ -29,7 +29,7 @@ ''' @author: Adolfo Gómez, dkmaster at dkmon dot com ''' - +from __future__ import unicode_literals # pylint: disable=unused-wildcard-import, wildcard-import import win32serviceutil # @UnresolvedImport, pylint: disable=import-error diff --git a/src/opengnsys/windows/__init__.py b/src/opengnsys/windows/__init__.py index c47fe7d..e662942 100644 --- a/src/opengnsys/windows/__init__.py +++ b/src/opengnsys/windows/__init__.py @@ -29,7 +29,7 @@ ''' @author: Adolfo Gómez, dkmaster at dkmon dot com ''' - +from __future__ import unicode_literals import os import sys diff --git a/src/opengnsys/windows/log.py b/src/opengnsys/windows/log.py index 16750ae..745fd03 100644 --- a/src/opengnsys/windows/log.py +++ b/src/opengnsys/windows/log.py @@ -29,7 +29,7 @@ ''' @author: Adolfo Gómez, dkmaster at dkmon dot com ''' - +from __future__ import unicode_literals import servicemanager # @UnresolvedImport, pylint: disable=import-error import logging diff --git a/src/opengnsys/windows/operations.py b/src/opengnsys/windows/operations.py index 7be4ce1..82b6522 100644 --- a/src/opengnsys/windows/operations.py +++ b/src/opengnsys/windows/operations.py @@ -29,7 +29,7 @@ ''' @author: Adolfo Gómez, dkmaster at dkmon dot com ''' - +from __future__ import unicode_literals import os import locale @@ -102,12 +102,12 @@ def getWindowsVersion(): ''' Returns Windows version. ''' - import winreg - reg = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion') + import _winreg + reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion') try: - data = '{} {}'.format(winreg.QueryValueEx(reg, 'ProductName')[0], winreg.QueryValueEx(reg, 'ReleaseId')[0]) + data = '{} {}'.format(_winreg.QueryValueEx(reg, 'ProductName')[0], _winreg.QueryValueEx(reg, 'ReleaseId')[0]) except Exception: - data = '{} {}'.format(winreg.QueryValueEx(reg, 'ProductName')[0], winreg.QueryValueEx(reg, 'CurrentBuildNumber')[0]) + data = '{} {}'.format(_winreg.QueryValueEx(reg, 'ProductName')[0], _winreg.QueryValueEx(reg, 'CurrentBuildNumber')[0]) reg.Close() return data @@ -200,7 +200,7 @@ def joinDomain(domain, ou, account, password, executeInOneStep=False): error = getErrorMessage(res) if res == 1355: error = "DC Is not reachable" - print(('{} {}'.format(res, error))) + print('{} {}'.format(res, error)) raise Exception('Error joining domain {}, with credentials {}/*****{}: {}, {}'.format(domain.value, account.value, ', under OU {}'.format(ou.value) if ou.value is not None else '', res, error)) diff --git a/windows/py2exe-wine-linux.sh b/windows/py2exe-wine-linux.sh new file mode 100755 index 0000000..68229b0 --- /dev/null +++ b/windows/py2exe-wine-linux.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +# We need: +# * Wine (32 bit) +# * winetricks (in some distributions) + +export WINEARCH=win32 WINEPREFIX=$PWD/wine WINEDEBUG=fixme-all +WINE=wine + +download() { + mkdir downloads + # Get needed software + cd downloads + wget -nd https://www.python.org/ftp/python/2.7.17/python-2.7.17.msi -O python-2.7.msi + wget -nd https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi + wget -nd https://bootstrap.pypa.io/get-pip.py + wget -nd https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.11.4/PyQt4-4.11.4-gpl-Py2.7-Qt4.8.7-x32.exe/download -O pyqt-install.exe + wget -nd https://prdownloads.sourceforge.net/nsis/nsis-3.05-setup.exe?download -O nsis-install.exe + wget -nd http://nsis.sourceforge.net/mediawiki/images/d/d7/NSIS_Simple_Firewall_Plugin_1.20.zip + cd .. +} + +install_python() { + if which winetricks &>/dev/null; then + echo "Setting up wine prefix (using winetricks)" + winetricks + fi + + cd downloads + echo "Installing python" + $WINE msiexec /qn /i python-2.7.msi + echo "Installing vc for python" + $WINE msiexec /qn /i VCForPython27.msi + + echo "Installing pyqt (needs X)" + $WINE pyqt-install.exe + echo "Installing nsis (needs X?)" + $WINE nsis-install.exe + + cd .. +} + +setup_pip() { + echo "Seting up pip..." + $WINE C:\\Python27\\python -m pip install --upgrade pip +} + +install_packages() { + echo "Installing pywin32" + $WINE C:\\Python27\\python -m pip install pywin32 + echo "Installing py2exe" + $WINE C:\\Python27\\python -m pip install py2exe_py2 + echo "Installing required packages" + $WINE C:\\Python27\\python -m pip install requests six + # Using easy_install instead of pip to install pycrypto + $WINE C:\\Python27\\Scripts\\easy_install http://www.voidspace.org.uk/python/pycrypto-2.6.1/pycrypto-2.6.1.win32-py2.7.exe + # Copy nsis required NSIS_Simple_Firewall_Plugin_1 + echo "Copying simple firewall plugin for nsis installer" + unzip -o downloads/NSIS_Simple_Firewall_Plugin_1.20.zip SimpleFC.dll -d $WINEPREFIX/drive_c/Program\ Files/NSIS/Plugins/x86-ansi/ + unzip -o downloads/NSIS_Simple_Firewall_Plugin_1.20.zip SimpleFC.dll -d $WINEPREFIX/drive_c/Program\ Files/NSIS/Plugins/x86-unicode/ +} + +download +install_python +setup_pip +install_packages + diff --git a/windows/pyinstaller-wine.sh b/windows/pyinstaller-wine.sh deleted file mode 100755 index 9d4b59f..0000000 --- a/windows/pyinstaller-wine.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -# We need: -# * Wine (64 bit) -# * winetricks (in some distributions) - -export WINEARCH=win64 WINEPREFIX=$PWD/wine WINEDEBUG=fixme-all -WINE=wine - -# Get needed software -download() { - mkdir -p downloads - cd downloads - wget -nd https://www.python.org/ftp/python/3.7.7/python-3.7.7-amd64.exe -O python3.msi - wget -nd https://download.visualstudio.microsoft.com/download/pr/5e397ebe-38b2-4e18-a187-ac313d07332a/00945fbb0a29f63183b70370043e249218249f83dbc82cd3b46c5646503f9e27/vs_BuildTools.exe - wget -nd https://prdownloads.sourceforge.net/nsis/nsis-3.05-setup.exe?download -O nsis-install.exe - wget -nd http://nsis.sourceforge.net/mediawiki/images/d/d7/NSIS_Simple_Firewall_Plugin_1.20.zip - cd .. -} - -install_python() { - cd downloads - echo "Installing python" - $WINE python3.msi /quiet TargetDir=C:\\Python37 PrependPath=1 - echo "Installing Build Tools for Visual Studio" - $WINE vs_BuildTools.exe - echo "Installing NSIS (needs X?)" - $WINE nsis-install.exe /S - cd .. -} - -setup_pip() { - echo "Setting up pip and setuptools" - $WINE pip install --upgrade pip - $WINE pip install --upgrade setuptools -} - -install_packages() { - echo "Installing PyQt5" - $WINE pip install PyQt5 - echo "Installing required packages" - $WINE pip install pycrypto requests six - # Using easy_install instead of pip to install pycrypto - $WINE pip install pycrypto - echo "Installing PyInstaller" - $WINE pip install PyInstaller - echo "Copying simple firewall plugin for nsis installer" - unzip -o downloads/NSIS_Simple_Firewall_Plugin_1.20.zip SimpleFC.dll -d $WINEPREFIX/drive_c/Program\ Files/NSIS/Plugins/x86-ansi/ - unzip -o downloads/NSIS_Simple_Firewall_Plugin_1.20.zip SimpleFC.dll -d $WINEPREFIX/drive_c/Program\ Files/NSIS/Plugins/x86-unicode/ -} - -download -install_python -setup_pip -install_packages -