From adcf25e7ba68d13f0ce3420d24fc91840b30e893 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 15 Aug 2025 17:48:21 +0100 Subject: Remove git based version handling --- klippy/util.py | 123 +-------------------------------------------------------- 1 file changed, 1 insertion(+), 122 deletions(-) (limited to 'klippy/util.py') diff --git a/klippy/util.py b/klippy/util.py index b43a7f1c..8ad8ccaa 100644 --- a/klippy/util.py +++ b/klippy/util.py @@ -4,7 +4,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import os, pty, fcntl, termios, signal, logging, json, time -import subprocess, traceback, shlex +import traceback ###################################################################### @@ -117,124 +117,3 @@ def get_cpu_info(): core_count = [k for k, v in lines].count("processor") model_name = dict(lines).get("model name", "?") return "%d core %s" % (core_count, model_name) - - -def get_version_from_file(klippy_src): - try: - with open(os.path.join(klippy_src, ".version")) as h: - return h.read().rstrip() - except IOError: - pass - return "?" - - -def _get_repo_info(gitdir): - repo_info = {"branch": "?", "remote": "?", "url": "?"} - prog_branch = ("git", "-C", gitdir, "branch", "--no-color") - try: - process = subprocess.Popen( - prog_branch, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - branch_list, err = process.communicate() - retcode = process.wait() - if retcode != 0: - logging.debug("Error running git branch: %s", err) - return repo_info - lines = str(branch_list.strip().decode()).split("\n") - for line in lines: - if line[0] == "*": - repo_info["branch"] = line[1:].strip() - break - else: - logging.debug("Unable to find current branch:\n%s", branch_list) - return repo_info - if repo_info["branch"].startswith("(HEAD detached"): - parts = repo_info["branch"].strip("()").split()[-1].split("/", 1) - if len(parts) != 2: - return repo_info - repo_info["remote"] = parts[0] - else: - key = "branch.%s.remote" % (repo_info["branch"],) - prog_config = ("git", "-C", gitdir, "config", "--get", key) - process = subprocess.Popen( - prog_config, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - remote_info, err = process.communicate() - retcode = process.wait() - if retcode != 0: - logging.debug("Error running git config: %s", err) - return repo_info - repo_info["remote"] = str(remote_info.strip().decode()) - prog_remote_url = ( - "git", - "-C", - gitdir, - "remote", - "get-url", - repo_info["remote"], - ) - process = subprocess.Popen( - prog_remote_url, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - remote_url, err = process.communicate() - retcode = process.wait() - if retcode != 0: - logging.debug("Error running git remote get-url: %s", err) - return repo_info - repo_info["url"] = str(remote_url.strip().decode()) - except: - logging.debug("Error fetching repo info: %s", traceback.format_exc()) - return repo_info - - -def get_git_version(from_file=True): - git_info = { - "version": "?", - "file_status": [], - "branch": "?", - "remote": "?", - "url": "?", - } - klippy_src = os.path.dirname(__file__) - - # Obtain version info from "git" program - gitdir = os.path.join(klippy_src, "..") - prog_desc = ( - "git", - "-C", - gitdir, - "describe", - "--always", - "--tags", - "--long", - "--dirty", - ) - prog_status = ("git", "-C", gitdir, "status", "--porcelain", "--ignored") - try: - process = subprocess.Popen( - prog_desc, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - ver, err = process.communicate() - retcode = process.wait() - if retcode == 0: - git_info["version"] = str(ver.strip().decode()) - process = subprocess.Popen( - prog_status, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - stat, err = process.communicate() - status = [l.split(None, 1) for l in str(stat.strip().decode()).split("\n")] - retcode = process.wait() - if retcode == 0: - git_info["file_status"] = status - else: - logging.debug("Error getting git status: %s", err) - git_info.update(_get_repo_info(gitdir)) - return git_info - else: - logging.debug("Error getting git version: %s", err) - except: - logging.debug("Exception on run: %s", traceback.format_exc()) - - if from_file: - git_info["version"] = get_version_from_file(klippy_src) - return git_info -- cgit v1.2.3-70-g09d2