From 1586f1a25c41fb6036a24b47cfa58e3e818b8a58 Mon Sep 17 00:00:00 2001 From: Brian Dolbec <dol...@gentoo.org> Date: Mon, 5 Dec 2016 11:27:15 -0800 Subject: [PATCH] repoman: Fix versioning system
Repoman had been showing the portage version. Which was the same for the last release. Copy the live versions code from portage, Modify as needed to get the correct tag info. Add portage version to --version output. --- repoman/pym/repoman/__init__.py | 70 +++++++++++++++++++++++++++++++++++++++++ repoman/pym/repoman/main.py | 3 +- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/repoman/pym/repoman/__init__.py b/repoman/pym/repoman/__init__.py index 5f0f9f8..b118ebe 100644 --- a/repoman/pym/repoman/__init__.py +++ b/repoman/pym/repoman/__init__.py @@ -1,6 +1,76 @@ import os.path +import subprocess +import sys +import time + +try: + import portage.const + import portage.proxy as proxy + from portage import _encodings, _shell_quote, _unicode_encode, _unicode_decode + from portage.const import PORTAGE_BASE_PATH, BASH_BINARY +except ImportError as e: + sys.stderr.write("\n\n") + sys.stderr.write("!!! Failed to complete portage imports. There are internal modules for\n") + sys.stderr.write("!!! portage and failure here indicates that you have a problem with your\n") + sys.stderr.write("!!! installation of portage. Please try a rescue portage located in the\n") + sys.stderr.write("!!! portage tree under '/usr/portage/sys-apps/portage/files/' (default).\n") + sys.stderr.write("!!! There is a README.RESCUE file that details the steps required to perform\n") + sys.stderr.write("!!! a recovery of portage.\n") + sys.stderr.write(" "+str(e)+"\n\n") + raise + + +VERSION = "HEAD" REPOMAN_BASE_PATH = os.path.join(os.sep, os.sep.join(os.path.realpath(__file__.rstrip("co")).split(os.sep)[:-3])) _not_installed = os.path.isfile(os.path.join(REPOMAN_BASE_PATH, ".repoman_not_installed")) + +if VERSION == 'HEAD': + class _LazyVersion(proxy.objectproxy.ObjectProxy): + def _get_target(self): + global VERSION + if VERSION is not self: + return VERSION + if os.path.isdir(os.path.join(PORTAGE_BASE_PATH, '.git')): + encoding = _encodings['fs'] + cmd = [BASH_BINARY, "-c", ("cd %s ; git describe --match repoman-* || exit $? ; " + \ + "if [ -n \"`git diff-index --name-only --diff-filter=M HEAD`\" ] ; " + \ + "then echo modified ; git rev-list --format=%%ct -n 1 HEAD ; fi ; " + \ + "exit 0") % _shell_quote(PORTAGE_BASE_PATH)] + cmd = [_unicode_encode(x, encoding=encoding, errors='strict') + for x in cmd] + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + output = _unicode_decode(proc.communicate()[0], encoding=encoding) + status = proc.wait() + if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK: + output_lines = output.splitlines() + if output_lines: + version_split = output_lines[0].split('-') + if len(version_split) > 1: + VERSION = version_split[1] + patchlevel = False + if len(version_split) > 2: + patchlevel = True + VERSION = "%s_p%s" % (VERSION, version_split[2]) + if len(output_lines) > 1 and output_lines[1] == 'modified': + head_timestamp = None + if len(output_lines) > 3: + try: + head_timestamp = long(output_lines[3]) + except ValueError: + pass + timestamp = long(time.time()) + if head_timestamp is not None and timestamp > head_timestamp: + timestamp = timestamp - head_timestamp + if not patchlevel: + VERSION = "%s_p0" % (VERSION,) + VERSION = "%s_p%d" % (VERSION, timestamp) + return VERSION + else: + print("NO output lines :(") + VERSION = 'HEAD' + return VERSION + VERSION = _LazyVersion() diff --git a/repoman/pym/repoman/main.py b/repoman/pym/repoman/main.py index 2c9445a..825a82e 100755 --- a/repoman/pym/repoman/main.py +++ b/repoman/pym/repoman/main.py @@ -36,6 +36,7 @@ from repoman.repos import RepoSettings from repoman.scanner import Scanner from repoman import utilities from repoman.modules.vcs.settings import VCSSettings +from repoman import VERSION if sys.hexversion >= 0x3000000: basestring = str @@ -62,7 +63,7 @@ def repoman_main(argv): sys.argv, qahelp, repoman_settings.get("REPOMAN_DEFAULT_OPTS", "")) if options.version: - print("Repoman", portage.VERSION) + print("Repoman", VERSION, "(portage-%s)" % portage.VERSION) sys.exit(0) logger = logging.getLogger() -- 2.9.3 -- Brian Dolbec <dolsen>