MissKatyPyro/update.py
yasirarism 68d006607f
Big Update And Some Fixing Code (#86)
- AutoFix Code Using DeepSource
- Fix os not defined when got error
- Fix Set Chat Photo (Only support photo)
- Fix Admins Permission Error
- Fix KeyError in Scraper
- Fix Help Module in Eval
- Fix Media Caption Too Long in IMDB
- Remove heroku support
- Some minor fix..
2023-06-22 12:52:30 +07:00

60 lines
1.8 KiB
Python

import logging
import os
from subprocess import run as srun
import requests
from dotenv import load_dotenv
LOGGER = logging.getLogger(__name__)
CONFIG_FILE_URL = os.environ.get("CONFIG_FILE_URL", "")
try:
if len(CONFIG_FILE_URL) == 0:
raise TypeError
try:
res = requests.get(CONFIG_FILE_URL)
if res.status_code == 200:
with open("config.env", "wb+") as f:
f.write(res.content)
else:
LOGGER.error(f"config.env err: {res.status_code}")
except Exception as e:
LOGGER.error(f"ENV_URL: {e}")
except:
pass
load_dotenv("config.env", override=True)
UPSTREAM_REPO_URL = os.environ.get("UPSTREAM_REPO_URL", "")
if len(UPSTREAM_REPO_URL) == 0:
UPSTREAM_REPO_URL = None
UPSTREAM_REPO_BRANCH = os.environ.get("UPSTREAM_REPO_BRANCH", "")
if len(UPSTREAM_REPO_BRANCH) == 0:
UPSTREAM_REPO_BRANCH = "master"
if UPSTREAM_REPO_URL is not None:
if os.path.exists(".git"):
srun(["rm", "-rf", ".git"], check=True)
update = srun(
[
f"git init -q \
&& git config --global user.email mail@yasir.eu.org \
&& git config --global user.name yasirarism \
&& git add . \
&& git commit -sm update -q \
&& git remote add origin {UPSTREAM_REPO_URL} \
&& git fetch origin -q \
&& git reset --hard origin/{UPSTREAM_REPO_BRANCH} -q"
],
shell=True,
check=True,
)
if update.returncode == 0:
LOGGER.error("Successfully updated with latest commit from UPSTREAM_REPO")
else:
LOGGER.error(
"Something went wrong while updating, check UPSTREAM_REPO if valid or not!"
)