You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

72 lines
1.4 KiB

import logging
import os
import shutil
import sys
import tempfile
from contextlib import contextmanager
from enum import Enum
from sys import platform as _platform
class OS(Enum):
UNKNOWN = "unknown"
LINUX = "linux"
MAC = "mac"
WIN = "win"
def get_os():
if _platform == "linux" or _platform == "linux2":
return OS.LINUX
elif _platform == "darwin":
return OS.MAC
elif _platform == "win32" or _platform == "win64":
return OS.WIN
else:
return OS.UNKNOWN
def get_python_version():
return sys.version_info[0], sys.version_info[1]
def check_pyinstaller():
return shutil.which("pyinstaller")
def check_node():
return shutil.which("node")
def check_yarn():
return shutil.which("yarn")
def setup_log(log_lvl=logging.INFO):
log = logging.getLogger(__name__)
if not log.hasHandlers():
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setFormatter(logging.Formatter('%(asctime)s %(message)s'))
log.addHandler(out_hdlr)
log.setLevel(log_lvl)
return log
@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(os.path.expanduser(newdir))
try:
yield
finally:
os.chdir(prevdir)
def create_temporary_copy(path, copy_name):
temp_dir = tempfile.gettempdir()
temp_path = os.path.join(temp_dir, copy_name)
shutil.copy2(path, temp_path)
return temp_path
log = setup_log()