Skip to content
Snippets Groups Projects

4.0.1 Patches,

Merged Iain Powrie requested to merge dev into master
2 files
+ 6
3
Compare changes
  • Side-by-side
  • Inline
Files
2
 
import contextlib
import os
import os
import re
import re
 
import winreg
import sys
import sys
import json
import json
import tempfile
import tempfile
@@ -93,16 +95,50 @@ class Helpers:
@@ -93,16 +95,50 @@ class Helpers:
if Helpers.check_file_exists(file):
if Helpers.check_file_exists(file):
file_time = os.path.getmtime(file)
file_time = os.path.getmtime(file)
# Check against 24 hours
# Check against 24 hours
if (time.time() - file_time) / 3600 > 24 * days:
return (time.time() - file_time) / 3600 > 24 * days
return True
else:
return False
logger.error(f"{file} does not exist")
logger.error(f"{file} does not exist")
return True
return True
def get_servers_root_dir(self):
def get_servers_root_dir(self):
return self.servers_dir
return self.servers_dir
 
@staticmethod
 
def which_java():
 
# Adapted from LeeKamentsky >>>
 
# https://github.com/LeeKamentsky/python-javabridge/blob/master/javabridge/locate.py
 
jdk_key_paths = (
 
"SOFTWARE\\JavaSoft\\JDK",
 
"SOFTWARE\\JavaSoft\\Java Development Kit",
 
)
 
for jdk_key_path in jdk_key_paths:
 
try:
 
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, jdk_key_path) as kjdk:
 
kjdk_values = (
 
dict( # pylint: disable=consider-using-dict-comprehension
 
[
 
winreg.EnumValue(kjdk, i)[:2]
 
for i in range(winreg.QueryInfoKey(kjdk)[1])
 
]
 
)
 
)
 
current_version = kjdk_values["CurrentVersion"]
 
kjdk_current = winreg.OpenKey(
 
winreg.HKEY_LOCAL_MACHINE, jdk_key_path + "\\" + current_version
 
)
 
kjdk_current_values = (
 
dict( # pylint: disable=consider-using-dict-comprehension
 
[
 
winreg.EnumValue(kjdk_current, i)[:2]
 
for i in range(winreg.QueryInfoKey(kjdk_current)[1])
 
]
 
)
 
)
 
return kjdk_current_values["JavaHome"]
 
except WindowsError as e: # pylint: disable=E0602
 
if e.errno == 2:
 
continue
 
raise
 
@staticmethod
@staticmethod
def check_internet():
def check_internet():
try:
try:
@@ -125,10 +161,7 @@ class Helpers:
@@ -125,10 +161,7 @@ class Helpers:
a_socket.close()
a_socket.close()
if result_of_check == 0:
return result_of_check == 0
return True
else:
return False
@staticmethod
@staticmethod
def check_server_conn(server_port):
def check_server_conn(server_port):
@@ -140,10 +173,7 @@ class Helpers:
@@ -140,10 +173,7 @@ class Helpers:
result_of_check = a_socket.connect_ex(location)
result_of_check = a_socket.connect_ex(location)
a_socket.close()
a_socket.close()
if result_of_check == 0:
return result_of_check == 0
return True
else:
return False
@staticmethod
@staticmethod
def cmdparse(cmd_in):
def cmdparse(cmd_in):
@@ -163,7 +193,6 @@ class Helpers:
@@ -163,7 +193,6 @@ class Helpers:
# Continue the loop.
# Continue the loop.
if char == " ":
if char == " ":
continue
continue
else:
cmd_index += 1
cmd_index += 1
cmd_out.append("")
cmd_out.append("")
new_param = False
new_param = False
@@ -348,7 +377,6 @@ class Helpers:
@@ -348,7 +377,6 @@ class Helpers:
common_path = pathlib.Path(os.path.commonpath([base, fileabs]))
common_path = pathlib.Path(os.path.commonpath([base, fileabs]))
if base == common_path:
if base == common_path:
return fileabs
return fileabs
else:
raise ValueError("Path traversal detected")
raise ValueError("Path traversal detected")
@staticmethod
@staticmethod
@@ -405,15 +433,8 @@ class Helpers:
@@ -405,15 +433,8 @@ class Helpers:
@staticmethod
@staticmethod
def check_root():
def check_root():
if Helpers.is_os_windows():
if Helpers.is_os_windows():
if ctypes.windll.shell32.IsUserAnAdmin() == 1:
return ctypes.windll.shell32.IsUserAnAdmin() == 1
return True
return os.geteuid() == 0
else:
return False
else:
if os.geteuid() == 0:
return True
else:
return False
@staticmethod
@staticmethod
def unzip_file(zip_path):
def unzip_file(zip_path):
@@ -491,9 +512,10 @@ class Helpers:
@@ -491,9 +512,10 @@ class Helpers:
# del any old session.lock file as this is a new session
# del any old session.lock file as this is a new session
try:
try:
 
with contextlib.suppress(FileNotFoundError):
os.remove(session_log_file)
os.remove(session_log_file)
except Exception as e:
except Exception as e:
logger.error(f"Deleting Session.lock failed with error: {e}")
Console.error(f"Deleting logs/session.log failed with error: {e}")
@staticmethod
@staticmethod
def get_time_as_string():
def get_time_as_string():
@@ -529,7 +551,6 @@ class Helpers:
@@ -529,7 +551,6 @@ class Helpers:
if os.path.exists(path) and os.path.isfile(path):
if os.path.exists(path) and os.path.isfile(path):
logger.debug(f"Found path: {path}")
logger.debug(f"Found path: {path}")
return True
return True
else:
return False
return False
@staticmethod
@staticmethod
@@ -551,7 +572,6 @@ class Helpers:
@@ -551,7 +572,6 @@ class Helpers:
if os.path.exists(path):
if os.path.exists(path):
logger.debug(f"Found path: {path}")
logger.debug(f"Found path: {path}")
return True
return True
else:
return False
return False
@staticmethod
@staticmethod
@@ -768,10 +788,7 @@ class Helpers:
@@ -768,10 +788,7 @@ class Helpers:
@staticmethod
@staticmethod
def is_os_windows():
def is_os_windows():
if os.name == "nt":
return os.name == "nt"
return True
else:
return False
@staticmethod
@staticmethod
def wtol_path(w_path):
def wtol_path(w_path):
@@ -946,7 +963,6 @@ class Helpers:
@@ -946,7 +963,6 @@ class Helpers:
# extracts archive to temp directory
# extracts archive to temp directory
zip_ref.extractall(temp_dir)
zip_ref.extractall(temp_dir)
return temp_dir
return temp_dir
else:
return False
return False
@staticmethod
@staticmethod
Loading