Added libs
This commit is contained in:
59
app/BKP/start.py
Normal file
59
app/BKP/start.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import os, sys
|
||||
import logging
|
||||
import shutil
|
||||
import pathlib
|
||||
import urllib.request
|
||||
import time
|
||||
from pathlib import Path
|
||||
import zipfile
|
||||
|
||||
root_dir = pathlib.Path(__file__).parent.resolve()
|
||||
logger = logging.getLogger("start")
|
||||
|
||||
def start():
|
||||
global logger
|
||||
logger.debug(f"---------------- START ----------------")
|
||||
logger.debug(f"Root path: {root_dir}")
|
||||
|
||||
pathlib.Path(os.path.join(root_dir, "libs")).mkdir(parents=True, exist_ok=True)
|
||||
download_app()
|
||||
from libs.app.utils import Utils, get_logger, create_venv, download_file, kargs_to_array
|
||||
create_venv()
|
||||
args = kargs_to_array()
|
||||
# args.append("updateApp=False") # NEVER SET TRUE
|
||||
# args.append("updateLibs=True")
|
||||
utils = Utils()
|
||||
|
||||
main_file_path = os.path.join(root_dir, "libs","app", "main.py")
|
||||
pid = utils.new_python_process(main_file_path, args)
|
||||
logger.info(f"Main process running. PID {pid} - Args: {args}")
|
||||
logger.info(f"---------------- END ----------------")
|
||||
|
||||
def download_app():
|
||||
url = f"{default_repository}/app/app.zip"
|
||||
path = os.path.join(root_dir, "libs", "app.zip")
|
||||
if(not os.path.exists(path)):
|
||||
logger.debug(f"Downloading from URL: {url} to {path}")
|
||||
urllib.request.urlretrieve(url, path)
|
||||
logger.debug(f"Extracting all from {path}")
|
||||
with zipfile.ZipFile(path, 'r') as zip_ref:
|
||||
zip_ref.extractall(Path(path).parent.absolute())
|
||||
|
||||
|
||||
|
||||
default_repository = "http://n0sys.duckdns.org:30303/libs"
|
||||
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
app_logs_path = os.path.join(root_dir, "logs", "app")
|
||||
shutil.rmtree(os.path.join(root_dir, "logs"), ignore_errors=True)
|
||||
pathlib.Path(app_logs_path).mkdir(parents=True, exist_ok=True)
|
||||
logger.addHandler(logging.FileHandler(os.path.join(app_logs_path,'start.log'), mode="a", encoding="utf-8"))
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
start()
|
||||
except Exception as e:
|
||||
logger.exception("ERROR")
|
||||
time.sleep(30)
|
||||
|
||||
Reference in New Issue
Block a user