From f5993e36be5b46c282c425f99ff221358b79734a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 19 Jan 2023 14:38:55 -0500 Subject: [PATCH] [11] add branch detection --- VERSION | 2 +- modules/util.py | 14 ++++++++++++++ plex_meta_manager.py | 11 ++++++++--- requirements.txt | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index c1f9d470..0ecf3020 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.3-develop10 +1.18.3-develop11 diff --git a/modules/util.py b/modules/util.py index ce57fadb..20f9814f 100644 --- a/modules/util.py +++ b/modules/util.py @@ -103,6 +103,20 @@ parental_labels = [f"{t.capitalize()}:{v}" for t in parental_types for v in pare previous_time = None start_time = None +def guess_branch(version, env_version, git_branch): + if git_branch: + return git_branch + elif env_version in ["nightly", "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 "nightly" + else: + return "master" + def current_version(version, env_version=None, nightly=False): if nightly or env_version == "nightly": return get_nightly() diff --git a/plex_meta_manager.py b/plex_meta_manager.py index f5bb7a02..8d518df8 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -6,6 +6,7 @@ from modules.logs import MyLogger try: import plexapi, requests, schedule + from git import Repo, InvalidGitRepositoryError from PIL import ImageFile from plexapi import server from plexapi.exceptions import NotFound @@ -80,6 +81,10 @@ def get_arg(env_str, default, arg_bool=False, arg_int=False): else: return default +try: + git_branch = Repo(path=".").head.ref.name +except InvalidGitRepositoryError: + git_branch = None env_version = get_arg("BRANCH_NAME", "master") is_docker = get_arg("PMM_DOCKER", False, arg_bool=True) is_linuxserver = get_arg("PMM_LINUXSERVER", False, arg_bool=True) @@ -163,6 +168,8 @@ with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "VERSION")) a if len(line) > 0: version = util.parse_version(line) break +branch = util.guess_branch(version, env_version, git_branch) +version = (version[0].replace("develop", branch), version[1].replace("develop", branch), version[2]) uuid_file = os.path.join(default_dir, "UUID") uuid_num = None @@ -196,9 +203,7 @@ def start(attrs): logger.info_center("|_| |_|\\___/_/\\_\\ |_| |_|\\___|\\__\\__,_| |_| |_|\\__,_|_| |_|\\__,_|\\__, |\\___|_| ") logger.info_center(" |___/ ") system_ver = "Docker" if is_docker else "Linuxserver" if is_linuxserver else f"Python {platform.python_version()}" - logger.info(f" Version: {version[0]} ({system_ver})") - logger.trace(f"BRANCH_NAME: {test_value}") - logger.trace(f"env_version: {env_version}") + logger.info(f" Version: {version[0]} ({system_ver}){f' (Git: {git_branch})' if git_branch else ''}") latest_version = util.current_version(version, env_version=env_version) 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: diff --git a/requirements.txt b/requirements.txt index 4bb4959f..5f7c22cc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,5 @@ retrying==1.3.4 pathvalidate==2.5.2 pillow==9.4.0 num2words==0.5.12 -psutil==5.9.4 \ No newline at end of file +psutil==5.9.4 +GitPython==3.1.30 \ No newline at end of file