MissKatyPyro/update.py
yasirarism 3bebdfee43
Add auto updater and fix genss because pillow v10 (#127)
* auto updater tess

* forgot

* fixx

* tess lagi

* pusing

* no cache

* ok

* Update update.py

* Update requirements.txt

* Update requirements.txt

* Lock pillow version

* Fix error

* Update __init__.py

* style: format code with black and isort (#126)

Format code with black and isort

This commit fixes the style issues introduced in 0188bba according to the output
from Black and isort.

Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/dbe242ae-b4d5-4a9a-8998-ba9fe569a4e0/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2023-07-02 12:26:26 +07:00

67 lines
2.1 KiB
Python

import logging
import os
import subprocess
import time
import dotenv
import requests
from git import Repo
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__)
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"CONFIG_FILE_URL: {e}")
except:
pass
dotenv.load_dotenv("config.env", override=True)
UPSTREAM_REPO_URL = os.environ.get("UPSTREAM_REPO_URL")
UPSTREAM_REPO_BRANCH = os.environ.get("UPSTREAM_REPO_BRANCH")
if all([UPSTREAM_REPO_URL, UPSTREAM_REPO_BRANCH]):
if os.path.exists(".git"):
subprocess.run(["rm", "-rf", ".git"])
try:
repo = Repo.init()
origin = repo.create_remote("upstream", UPSTREAM_REPO_URL)
origin.fetch()
repo.create_head(UPSTREAM_REPO_BRANCH, origin.refs[UPSTREAM_REPO_BRANCH])
repo.heads[UPSTREAM_REPO_BRANCH].set_tracking_branch(
origin.refs[UPSTREAM_REPO_BRANCH]
)
repo.heads[UPSTREAM_REPO_BRANCH].checkout(True)
ups_rem = repo.remote("upstream")
ups_rem.fetch(UPSTREAM_REPO_BRANCH)
LOGGER.info(f"Successfully update with latest branch > {UPSTREAM_REPO_BRANCH}")
except Exception as e:
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"
)