mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 17:44:50 +00:00
Update update.py
This commit is contained in:
parent
7af42ce6d5
commit
0188bbab2a
1 changed files with 45 additions and 39 deletions
84
update.py
84
update.py
|
|
@ -1,52 +1,58 @@
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from subprocess import run as srun
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from dotenv import load_dotenv
|
from git import Repo
|
||||||
|
import logging, os, dotenv, subprocess, time
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
format='[%(levelname)s] - [%(asctime)s] [%(filename)s:%(lineno)d] %(message)s',
|
||||||
|
handlers=[logging.FileHandler('log.txt'), logging.StreamHandler()],
|
||||||
|
level=logging.INFO
|
||||||
|
)
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONFIG_FILE_URL = os.environ.get("CONFIG_FILE_URL", "")
|
CONFIG_FILE_URL = os.environ.get("CONFIG_FILE_URL")
|
||||||
if len(CONFIG_FILE_URL) != 0:
|
try:
|
||||||
|
if len(CONFIG_FILE_URL) == 0:
|
||||||
|
raise TypeError
|
||||||
try:
|
try:
|
||||||
res = requests.get(CONFIG_FILE_URL)
|
res = requests.get(CONFIG_FILE_URL)
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
with open("config.env", "wb+") as c:
|
with open("config.env", "wb+") as f:
|
||||||
c.write(res.content)
|
f.write(res.content)
|
||||||
LOGGER.info("Config env has successfully writed")
|
|
||||||
else:
|
else:
|
||||||
LOGGER.info(
|
LOGGER.error(f"config.env err: {res.status_code}")
|
||||||
f"config.env error: {res.status_code}\nMake sure ur config.env found in workdir, will continuing with config.env on workdir"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOGGER.error(f"Something wrong while downloading config.env > {str(e)}")
|
LOGGER.error(f"CONFIG_FILE_URL: {e}")
|
||||||
sys.exit(0)
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
load_dotenv('config.env', override=True)
|
dotenv.load_dotenv("config.env", override=True)
|
||||||
|
|
||||||
UPSTREAM_REPO_URL = os.environ.get("UPSTREAM_REPO_URL", "")
|
UPSTREAM_REPO_URL = os.environ.get('UPSTREAM_REPO_URL')
|
||||||
if len(UPSTREAM_REPO_URL) == 0:
|
UPSTREAM_REPO_BRANCH = os.environ.get('UPSTREAM_REPO_BRANCH')
|
||||||
UPSTREAM_REPO_URL = None
|
|
||||||
|
|
||||||
UPSTREAM_REPO_BRANCH = os.environ.get("UPSTREAM_REPO_BRANCH", "")
|
if all([UPSTREAM_REPO_URL, UPSTREAM_REPO_BRANCH]):
|
||||||
if len(UPSTREAM_REPO_BRANCH) == 0:
|
|
||||||
UPSTREAM_REPO_BRANCH = None
|
|
||||||
|
|
||||||
if UPSTREAM_REPO_URL is not None and UPSTREAM_REPO_BRANCH is not None:
|
|
||||||
if os.path.exists('.git'):
|
if os.path.exists('.git'):
|
||||||
srun(["rm", "-rf", ".git"])
|
subprocess.run(["rm", "-rf", ".git"])
|
||||||
update = srun([f"git init -q \
|
|
||||||
&& git config --global user.email mail@yasir.eu.org \
|
try:
|
||||||
&& git config --global user.name YasirArisM \
|
repo = Repo.init()
|
||||||
&& git add . \
|
origin = repo.create_remote("upstream", UPSTREAM_REPO_URL)
|
||||||
&& git commit -sm update -q \
|
origin.fetch()
|
||||||
&& git remote add origin {UPSTREAM_REPO_URL} \
|
repo.create_head(UPSTREAM_REPO_BRANCH, origin.refs[UPSTREAM_REPO_BRANCH])
|
||||||
&& git fetch origin -q \
|
repo.heads[UPSTREAM_REPO_BRANCH].set_tracking_branch(origin.refs[UPSTREAM_REPO_BRANCH])
|
||||||
&& git reset --hard origin/{UPSTREAM_REPO_BRANCH} -q"], shell=True)
|
repo.heads[UPSTREAM_REPO_BRANCH].checkout(True)
|
||||||
if update.returncode == 0:
|
ups_rem = repo.remote("upstream")
|
||||||
LOGGER.info(f'Successfully updated with latest commit branch > {UPSTREAM_REPO_BRANCH}')
|
ups_rem.fetch(UPSTREAM_REPO_BRANCH)
|
||||||
else:
|
LOGGER.info(f"Successfully update with latest branch > {UPSTREAM_REPO_BRANCH}")
|
||||||
LOGGER.error(f'Something went wrong while updating, check UPSTREAM_REPO_URL if valid or not! return code: {update.returncode}')
|
except Exception as e:
|
||||||
sys.exit(1)
|
LOGGER.error(e)
|
||||||
|
pass
|
||||||
|
# time.sleep(6)
|
||||||
|
# update = subprocess.run(['pip3', 'install', '-U', '-r', 'requirements.txt'])
|
||||||
|
# if update.returncode == 0:
|
||||||
|
# LOGGER.info("Successfully update package pip python")
|
||||||
|
#else:
|
||||||
|
# LOGGER.warning("Unsuccessfully update package pip python")
|
||||||
|
else:
|
||||||
|
LOGGER.warning("UPSTREAM_REPO_URL or UPSTREAM_REPO_BRANCH is not defined, Skipping auto update")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue