Spaces:
Runtime error
Runtime error
File size: 2,210 Bytes
4712303 7741f2a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import platform
import os
from mainLogic import error
from mainLogic.utils.process import shell
from mainLogic.utils.glv import Global
# 0 - linux
# 1 - windows
# 2 - mac (currently not supported)
class SysFunc:
def __init__(self,os=1 if "Windows" in platform.system() else 0 if "Linux" in platform.system() else -1):
if os == -1:
raise Exception("UnsupportedOS")
self.os = os
def create_dir(self,dirName,verbose=False):
try:
if not os.path.exists(dirName):
if verbose: Global.dprint(f"Creating directory {dirName}")
os.makedirs(dirName)
except:
if verbose: Global.errprint(f"Could not make directory {dirName}. Exiting...")
error.errorList["couldNotMakeDir"]["func"](dirName)
exit(error.errorList["couldNotMakeDir"]["code"])
if verbose: Global.dprint(f"Directory {dirName} created")
def clear(self):
if self.os == 0:
os.system("clear")
elif self.os == 1:
os.system("cls")
else:
raise Exception("UnsupportedOS")
def which(self,program):
if self.os == 0:
if shell('which',stderr="",stdout="") != 1 and shell('which',stderr="",stdout="") != 255:
error.errorList["dependencyNotFound"]["func"]('which')
exit(error.errorList["dependencyNotFound"]["code"])
else:
self.whichPresent = True
return shell(f"which {program}",stderr="",stdout="")
elif self.os == 1:
if shell('where',stderr="",stdout="") != 2:
error.errorList["dependencyNotFound"]["func"]('where')
exit(error.errorList["dependencyNotFound"]["code"])
else:
self.whichPresent = True
return shell(f"where {program}" , stderr="",stdout="")
else:
raise Exception("UnsupportedOS")
@staticmethod
def modify_path(path):
expanded_path = os.path.expandvars(path)
absolute_path = os.path.abspath(expanded_path)
modified_path = absolute_path.replace(os.sep, '/')
return modified_path
|