From fee197ce4b350f9bcd68beca90d2feb82ad9e6cc Mon Sep 17 00:00:00 2001 From: 5weedHome Date: Wed, 2 Sep 2020 13:45:14 +0300 Subject: [PATCH] run_command ('java -version') malfunction --- checks_develop.py | 52 ++++++++++++++++++++++++++ install_develop.py | 93 ++++++++++++++++++++++++++++++++++++++++++++++ run-develop.py | 8 +--- 3 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 checks_develop.py create mode 100644 install_develop.py diff --git a/checks_develop.py b/checks_develop.py new file mode 100644 index 00000000..13fa88a7 --- /dev/null +++ b/checks_develop.py @@ -0,0 +1,52 @@ +import sys +import subprocess +import ctypes + +def is_admin(): + try: + return ctypes.windll.shell32.IsUserAnAdmin() + except: + return False + +def check_nodejs_version(): + nodejs_version = run_command('node -v') + if nodejs_version == '': + return nodejs_version + + nodejs_cur_version = int(nodejs_version.split('.')[0][1:]) + return nodejs_cur_version + +def check_java_bitness(): + java_version = run_command('Java -version') + if java_version == '': + return java_version + elif java_version.find('64-Bit') == -1: + return 'x32' + elif java_version.find('32-Bit') == -1: + return 'x64' + +def run_command(sCommand): + popen = subprocess.Popen(sCommand, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + result = '' + try: + stdout, stderr = popen.communicate() + popen.wait() + if sCommand == 'node -v': + result = stdout.strip().decode("utf-8") + elif sCommand == 'java -version': + result = stdout.strip().decode("utf-8") + stderr.strip().decode("utf-8") + finally: + popen.stdout.close() + popen.stderr.close() + + return result + +try: + if is_admin(): + run_command('Java -version') + #run_command('node -v') + else: + ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(''.join(sys.argv)), None, 1) + sys.exit() +except SystemExit: + input("Ignoring SystemExit. Press Enter to continue...") \ No newline at end of file diff --git a/install_develop.py b/install_develop.py new file mode 100644 index 00000000..7fddfab0 --- /dev/null +++ b/install_develop.py @@ -0,0 +1,93 @@ +import sys +sys.path.append('../build_tools/scripts') +import os +import base +import subprocess +import ctypes +import checks_develop + +def is_admin(): + try: + return ctypes.windll.shell32.IsUserAnAdmin() + except: + return False + +def installingProgram(sProgram): + if sProgram == 'Node.js': + print("Installing Node.js...") + base.download("https://nodejs.org/dist/latest-v10.x/node-v10.22.0-x64.msi", './nodejs.msi') + code = subprocess.call('msiexec.exe /i nodejs.msi /qn', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + if code == 0: + print("Install success!") + base.delete_file('./nodejs.msi') + return True + else: + print("Error!") + base.delete_file('./nodejs.msi') + return False + elif sProgram == 'Java': + print("Installing Java...") + base.download("https://javadl.oracle.com/webapps/download/AutoDL?BundleId=242990_a4634525489241b9a9e1aa73d9e118e6", './java.exe') + code = subprocess.call('java.exe /s', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + if code == 0: + print("Install success!") + base.delete_file('./java.exe') + return True + else: + print("Error!") + base.delete_file('./java.exe') + return False + +def deleteProgram(sName): + if is_admin(): + print("Deleting " + sName + "...") + code = subprocess.call('wmic product where name="' + sName + '" call uninstall', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + if code == 0: + print("Delete success!") + else: + print("Error!") + else: + ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(''.join(sys.argv)), None, 1) + sys.exit() + +def installNodejs(installedVersion): + if installedVersion == '': + print('Node.js not found.') + else: + print('Installed Node.js version: ' + str(installedVersion)) + + nodejs_min_version = 8 + nodejs_max_version = 10 + if (installedVersion == ''): + return installingProgram('Node.js') + elif (nodejs_min_version > installedVersion or installedVersion > nodejs_max_version): + print('Node.js version must be 8.x to 10.x') + deleteProgram('Node.js') + return installingProgram('Node.js') + else: + print('Valid Node.js version') + return True + +def installJava(javaBitness): + if javaBitness == '': + print('Java not found.') + return installingProgram('Java') + elif javaBitness == 'x32': + print('Installed java: ' + javaBitness) + print('Java bitness must be x64') + return installingProgram('Java') + elif javaBitness == 'x64': + print('Valid java version.') + return True + +try: + if is_admin(): + base.print_info('Check Node.js version') + installNodejs(checks_develop.check_nodejs_version()) + base.print_info('Check Java bitness') + installJava(checks_develop.check_java_bitness()) + else: + ctypes.windll.shell32.ShellExecuteW(None, u"runas", unicode(sys.executable), unicode(''.join(sys.argv)), None, 1) + sys.exit() +except SystemExit: + input("Ignoring SystemExit. Press Enter to continue...") diff --git a/run-develop.py b/run-develop.py index 1198d1bc..ffa71b45 100755 --- a/run-develop.py +++ b/run-develop.py @@ -2,7 +2,7 @@ import sys sys.path.append('../build_tools/scripts') import os import base -import check_programs +import install_develop def install_module(path): base.print_info('Install: ' + path) @@ -35,11 +35,7 @@ def run_integration_example(): base.cmd_in_dir('../document-server-integration/web/documentserver-example/nodejs', 'python', ['run-develop.py']) try: - base.print_info('check Node.js version') - if (True != check_programs.check_nodejs_version()): - exit(0) - base.print_info('check Java bitness version') - if (True != check_programs.check_java_bitness()): + if (True != base.cmd_in_dir('../', 'python', ['install_develop.py'])): exit(0) platform = base.host_platform()