mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-08 21:06:28 +08:00
More info on versions
This commit is contained in:
parent
174f7cbf67
commit
27a04c5634
8 changed files with 129 additions and 15 deletions
2
.github/workflows/develop.yml
vendored
2
.github/workflows/develop.yml
vendored
|
@ -46,6 +46,8 @@ jobs:
|
||||||
with:
|
with:
|
||||||
context: ./
|
context: ./
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
|
build-args: |
|
||||||
|
"BRANCH_NAME=develop"
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/qbit_manage:develop
|
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/qbit_manage:develop
|
||||||
|
|
2
.github/workflows/version.yml
vendored
2
.github/workflows/version.yml
vendored
|
@ -14,6 +14,8 @@ jobs:
|
||||||
|
|
||||||
- name: Check Out Repo
|
- name: Check Out Repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
|
|
26
Dockerfile
26
Dockerfile
|
@ -1,13 +1,27 @@
|
||||||
FROM python:3.10-alpine
|
FROM python:3.11-slim-buster
|
||||||
|
ARG BRANCH_NAME=master
|
||||||
# install packages
|
ENV BRANCH_NAME ${BRANCH_NAME}
|
||||||
RUN apk add --no-cache gcc g++ libxml2-dev libxslt-dev shadow bash curl wget jq grep sed coreutils findutils unzip p7zip ca-certificates
|
ENV TINI_VERSION v0.19.0
|
||||||
|
ENV QBM_DOCKER True
|
||||||
|
|
||||||
COPY requirements.txt /
|
COPY requirements.txt /
|
||||||
|
|
||||||
RUN echo "**** install python packages ****" \
|
# install packages
|
||||||
|
RUN echo "**** install system packages ****" \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get upgrade -y --no-install-recommends \
|
||||||
|
&& apt-get install -y tzdata --no-install-recommends \
|
||||||
|
&& apt-get install -y --no-cache gcc g++ libxml2-dev libxslt-dev shadow bash curl wget jq grep sed coreutils findutils unzip p7zip ca-certificates \
|
||||||
|
&& wget -O /tini https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-"$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
|
||||||
|
&& chmod +x /tini \
|
||||||
&& pip3 install --no-cache-dir --upgrade --requirement /requirements.txt \
|
&& pip3 install --no-cache-dir --upgrade --requirement /requirements.txt \
|
||||||
&& rm -rf /requirements.txt /tmp/* /var/tmp/*
|
&& apt-get --purge autoremove gcc g++ libxml2-dev libxslt-dev libz-dev -y \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get check \
|
||||||
|
&& apt-get -f install \
|
||||||
|
&& apt-get autoclean \
|
||||||
|
&& rm -rf /requirements.txt /tmp/* /var/tmp/* /var/lib/apt/lists/*
|
||||||
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
3.6.3
|
3.6.3-develop1
|
||||||
|
|
|
@ -13,8 +13,10 @@ version_file_path = os.path.join(project_dir, "..", "VERSION")
|
||||||
with open(version_file_path) as f:
|
with open(version_file_path) as f:
|
||||||
version_str = f.read().strip()
|
version_str = f.read().strip()
|
||||||
|
|
||||||
|
# Get only the first 3 digits
|
||||||
|
version_str_split = version_str.rsplit("-", 1)[0]
|
||||||
# Convert the version string to a tuple of integers
|
# Convert the version string to a tuple of integers
|
||||||
__version_info__ = tuple(map(int, version_str.split(".")))
|
__version_info__ = tuple(map(int, version_str_split.split(".")))
|
||||||
|
|
||||||
# Define the version string using the version_info tuple
|
# Define the version string using the version_info tuple
|
||||||
__version__ = ".".join(str(i) for i in __version_info__)
|
__version__ = ".".join(str(i) for i in __version_info__)
|
||||||
|
|
|
@ -7,6 +7,7 @@ import signal
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import requests
|
||||||
import ruamel.yaml
|
import ruamel.yaml
|
||||||
|
|
||||||
logger = logging.getLogger("qBit Manage")
|
logger = logging.getLogger("qBit Manage")
|
||||||
|
@ -71,6 +72,64 @@ class TorrentMessages:
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def guess_branch(version, env_version, git_branch):
|
||||||
|
if git_branch:
|
||||||
|
return git_branch
|
||||||
|
elif env_version == "develop":
|
||||||
|
return env_version
|
||||||
|
elif version[2] > 0:
|
||||||
|
dev_version = get_develop()
|
||||||
|
if version[1] != dev_version[1] or version[2] <= dev_version[2]:
|
||||||
|
return "develop"
|
||||||
|
else:
|
||||||
|
return "master"
|
||||||
|
|
||||||
|
|
||||||
|
def current_version(version, branch=None):
|
||||||
|
if branch == "develop":
|
||||||
|
return get_develop()
|
||||||
|
elif version[2] > 0:
|
||||||
|
new_version = get_develop()
|
||||||
|
if version[1] != new_version[1] or new_version[2] >= version[2]:
|
||||||
|
return new_version
|
||||||
|
else:
|
||||||
|
return get_master()
|
||||||
|
|
||||||
|
|
||||||
|
develop_version = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_develop():
|
||||||
|
global develop_version
|
||||||
|
if develop_version is None:
|
||||||
|
develop_version = get_version("develop")
|
||||||
|
return develop_version
|
||||||
|
|
||||||
|
|
||||||
|
master_version = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_master():
|
||||||
|
global master_version
|
||||||
|
if master_version is None:
|
||||||
|
master_version = get_version("master")
|
||||||
|
return master_version
|
||||||
|
|
||||||
|
|
||||||
|
def get_version(level):
|
||||||
|
try:
|
||||||
|
url = f"https://raw.githubusercontent.com/StuffAnThings/qbit_manage/{level}/VERSION"
|
||||||
|
return parse_version(requests.get(url).content.decode().strip(), text=level)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
return "Unknown", "Unknown", 0
|
||||||
|
|
||||||
|
|
||||||
|
def parse_version(version, text="develop"):
|
||||||
|
version = version.replace("develop", text)
|
||||||
|
split_version = version.split(f"-{text}")
|
||||||
|
return version, split_version[0], int(split_version[1]) if len(split_version) > 1 else 0
|
||||||
|
|
||||||
|
|
||||||
class check:
|
class check:
|
||||||
"""Check for attributes in config."""
|
"""Check for attributes in config."""
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
@ -166,16 +167,23 @@ parser.add_argument("-w", "--width", dest="width", help="Screen Width (Default:
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
static_envs = []
|
||||||
|
test_value = None
|
||||||
|
|
||||||
|
|
||||||
def get_arg(env_str, default, arg_bool=False, arg_int=False):
|
def get_arg(env_str, default, arg_bool=False, arg_int=False):
|
||||||
"""Get argument from environment variable or command line argument."""
|
global test_value
|
||||||
env_vars = [env_str] if not isinstance(env_str, list) else env_str
|
env_vars = [env_str] if not isinstance(env_str, list) else env_str
|
||||||
final_value = None
|
final_value = None
|
||||||
|
static_envs.extend(env_vars)
|
||||||
for env_var in env_vars:
|
for env_var in env_vars:
|
||||||
env_value = os.environ.get(env_var)
|
env_value = os.environ.get(env_var)
|
||||||
|
if env_var == "BRANCH_NAME":
|
||||||
|
test_value = env_value
|
||||||
if env_value is not None:
|
if env_value is not None:
|
||||||
final_value = env_value
|
final_value = env_value
|
||||||
break
|
break
|
||||||
if final_value is not None:
|
if final_value or (arg_int and final_value == 0):
|
||||||
if arg_bool:
|
if arg_bool:
|
||||||
if final_value is True or final_value is False:
|
if final_value is True or final_value is False:
|
||||||
return final_value
|
return final_value
|
||||||
|
@ -184,13 +192,28 @@ def get_arg(env_str, default, arg_bool=False, arg_int=False):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif arg_int:
|
elif arg_int:
|
||||||
return int(final_value)
|
try:
|
||||||
|
return int(final_value)
|
||||||
|
except ValueError:
|
||||||
|
return default
|
||||||
else:
|
else:
|
||||||
return str(final_value)
|
return str(final_value)
|
||||||
else:
|
else:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from git import Repo, InvalidGitRepositoryError
|
||||||
|
|
||||||
|
try:
|
||||||
|
git_branch = Repo(path=".").head.ref.name # noqa
|
||||||
|
except InvalidGitRepositoryError:
|
||||||
|
git_branch = None
|
||||||
|
except ImportError:
|
||||||
|
git_branch = None
|
||||||
|
|
||||||
|
env_version = get_arg("BRANCH_NAME", "master")
|
||||||
|
is_docker = get_arg("QBM_DOCKER", False, arg_bool=True)
|
||||||
run = get_arg("QBT_RUN", args.run, arg_bool=True)
|
run = get_arg("QBT_RUN", args.run, arg_bool=True)
|
||||||
sch = get_arg("QBT_SCHEDULE", args.min)
|
sch = get_arg("QBT_SCHEDULE", args.min)
|
||||||
startupDelay = get_arg("QBT_STARTUP_DELAY", args.startupDelay)
|
startupDelay = get_arg("QBT_STARTUP_DELAY", args.startupDelay)
|
||||||
|
@ -306,13 +329,15 @@ def my_except_hook(exctype, value, tbi):
|
||||||
|
|
||||||
sys.excepthook = my_except_hook
|
sys.excepthook = my_except_hook
|
||||||
|
|
||||||
version = "Unknown"
|
version = ("Unknown", "Unknown", 0)
|
||||||
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "VERSION")) as handle:
|
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "VERSION")) as handle:
|
||||||
for line in handle.readlines():
|
for line in handle.readlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if len(line) > 0:
|
if len(line) > 0:
|
||||||
version = line
|
version = util.parse_version(line)
|
||||||
break
|
break
|
||||||
|
branch = util.guess_branch(version, env_version, git_branch)
|
||||||
|
version = (version[0].replace("develop", branch), version[1].replace("develop", branch), version[2])
|
||||||
|
|
||||||
|
|
||||||
def start_loop():
|
def start_loop():
|
||||||
|
@ -521,8 +546,17 @@ if __name__ == "__main__":
|
||||||
logger.info_center(r" \__, |_.__/|_|\__| |_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|") # noqa: W605
|
logger.info_center(r" \__, |_.__/|_|\__| |_| |_| |_|\__,_|_| |_|\__,_|\__, |\___|") # noqa: W605
|
||||||
logger.info_center(" | | ______ __/ | ") # noqa: W605
|
logger.info_center(" | | ______ __/ | ") # noqa: W605
|
||||||
logger.info_center(" |_| |______| |___/ ") # noqa: W605
|
logger.info_center(" |_| |______| |___/ ") # noqa: W605
|
||||||
logger.info(f" Version: {version}")
|
system_ver = "Docker" if is_docker else f"Python {platform.python_version()}"
|
||||||
|
logger.info(f" Version: {version[0]} ({system_ver}){f' (Git: {git_branch})' if git_branch else ''}")
|
||||||
|
latest_version = util.current_version(version, branch=branch)
|
||||||
|
new_version = (
|
||||||
|
latest_version[0]
|
||||||
|
if latest_version and (version[1] != latest_version[1] or (version[2] and version[2] < latest_version[2]))
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
if new_version:
|
||||||
|
logger.info(f" Newest Version: {new_version}")
|
||||||
|
logger.info(f" Platform: {platform.platform()}")
|
||||||
logger.separator(loglevel="DEBUG")
|
logger.separator(loglevel="DEBUG")
|
||||||
logger.debug(f" --run (QBT_RUN): {run}")
|
logger.debug(f" --run (QBT_RUN): {run}")
|
||||||
logger.debug(f" --schedule (QBT_SCHEDULE): {sch}")
|
logger.debug(f" --schedule (QBT_SCHEDULE): {sch}")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
bencodepy==0.9.5
|
bencodepy==0.9.5
|
||||||
flake8==6.0.0
|
flake8==6.0.0
|
||||||
|
GitPython==3.1.31
|
||||||
pre-commit==3.3.2
|
pre-commit==3.3.2
|
||||||
qbittorrent-api==2023.4.47
|
qbittorrent-api==2023.4.47
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
|
|
Loading…
Add table
Reference in a new issue