MissKatyPyro/update.py
deepsource-autofix[bot] 2aa93bb4d5
style: format code with isort, Ruff Formatter and Yapf (#300)
* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in f9f107e according to the output
from isort, Ruff Formatter and Yapf.

Details: None

* refactor: autofix issues in 2 files

Resolved issues in the following files with DeepSource Autofix:
1. misskaty/plugins/download_upload.py
2. misskaty/plugins/nightmodev2.py

* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in 1bc1345 according to the output
from isort, Ruff Formatter and Yapf.

Details: https://github.com/yasirarism/MissKatyPyro/pull/300

* refactor: autofix issues in 2 files

Resolved issues in the following files with DeepSource Autofix:
1. misskaty/plugins/dev.py
2. misskaty/plugins/misc_tools.py

* style: format code with isort, Ruff Formatter and Yapf

This commit fixes the style issues introduced in 58d2f1a according to the output
from isort, Ruff Formatter and Yapf.

Details: https://github.com/yasirarism/MissKatyPyro/pull/300

---------

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Yasir Aris M <git@yasirdev.my.id>
2024-07-30 11:52:58 +07:00

69 lines
2 KiB
Python

import os
import subprocess
from logging import INFO, StreamHandler, basicConfig, getLogger, handlers
import dotenv
import requests
from git import Repo
if os.path.exists("MissKatyLogs.txt"):
with open("MissKatyLogs.txt", "r+") as f:
f.truncate(0)
basicConfig(
level=INFO,
format="[%(levelname)s] - [%(asctime)s - %(name)s - %(message)s] -> [%(module)s:%(lineno)d]",
datefmt="%d-%b-%y %H:%M:%S",
handlers=[
handlers.RotatingFileHandler(
"MissKatyLogs.txt", mode="w+", maxBytes=5242880, backupCount=1
),
StreamHandler(),
],
)
LOGGER = getLogger("MissKaty")
ENV_URL = os.environ.get("ENV_URL")
try:
if len(ENV_URL) == 0:
raise TypeError
try:
res = requests.get(ENV_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
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"], check=True)
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)
else:
LOGGER.warning(
"UPSTREAM_REPO_URL or UPSTREAM_REPO_BRANCH is not defined, Skipping auto update"
)