Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] repoman: Fix versioning system
Date: Mon, 05 Dec 2016 19:42:15
Message-Id: 20161205114210.5870c4ce.dolsen@gentoo.org
1 From 1586f1a25c41fb6036a24b47cfa58e3e818b8a58 Mon Sep 17 00:00:00 2001
2 From: Brian Dolbec <dolsen@g.o>
3 Date: Mon, 5 Dec 2016 11:27:15 -0800
4 Subject: [PATCH] repoman: Fix versioning system
5
6 Repoman had been showing the portage version. Which was the same for the last release.
7 Copy the live versions code from portage, Modify as needed to get the correct tag info.
8 Add portage version to --version output.
9 ---
10 repoman/pym/repoman/__init__.py | 70 +++++++++++++++++++++++++++++++++++++++++
11 repoman/pym/repoman/main.py | 3 +-
12 2 files changed, 72 insertions(+), 1 deletion(-)
13
14 diff --git a/repoman/pym/repoman/__init__.py b/repoman/pym/repoman/__init__.py
15 index 5f0f9f8..b118ebe 100644
16 --- a/repoman/pym/repoman/__init__.py
17 +++ b/repoman/pym/repoman/__init__.py
18 @@ -1,6 +1,76 @@
19
20 import os.path
21 +import subprocess
22 +import sys
23 +import time
24 +
25 +try:
26 + import portage.const
27 + import portage.proxy as proxy
28 + from portage import _encodings, _shell_quote, _unicode_encode, _unicode_decode
29 + from portage.const import PORTAGE_BASE_PATH, BASH_BINARY
30 +except ImportError as e:
31 + sys.stderr.write("\n\n")
32 + sys.stderr.write("!!! Failed to complete portage imports. There are internal modules for\n")
33 + sys.stderr.write("!!! portage and failure here indicates that you have a problem with your\n")
34 + sys.stderr.write("!!! installation of portage. Please try a rescue portage located in the\n")
35 + sys.stderr.write("!!! portage tree under '/usr/portage/sys-apps/portage/files/' (default).\n")
36 + sys.stderr.write("!!! There is a README.RESCUE file that details the steps required to perform\n")
37 + sys.stderr.write("!!! a recovery of portage.\n")
38 + sys.stderr.write(" "+str(e)+"\n\n")
39 + raise
40 +
41 +
42 +VERSION = "HEAD"
43
44 REPOMAN_BASE_PATH = os.path.join(os.sep, os.sep.join(os.path.realpath(__file__.rstrip("co")).split(os.sep)[:-3]))
45
46 _not_installed = os.path.isfile(os.path.join(REPOMAN_BASE_PATH, ".repoman_not_installed"))
47 +
48 +if VERSION == 'HEAD':
49 + class _LazyVersion(proxy.objectproxy.ObjectProxy):
50 + def _get_target(self):
51 + global VERSION
52 + if VERSION is not self:
53 + return VERSION
54 + if os.path.isdir(os.path.join(PORTAGE_BASE_PATH, '.git')):
55 + encoding = _encodings['fs']
56 + cmd = [BASH_BINARY, "-c", ("cd %s ; git describe --match repoman-* || exit $? ; " + \
57 + "if [ -n \"`git diff-index --name-only --diff-filter=M HEAD`\" ] ; " + \
58 + "then echo modified ; git rev-list --format=%%ct -n 1 HEAD ; fi ; " + \
59 + "exit 0") % _shell_quote(PORTAGE_BASE_PATH)]
60 + cmd = [_unicode_encode(x, encoding=encoding, errors='strict')
61 + for x in cmd]
62 + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
63 + stderr=subprocess.STDOUT)
64 + output = _unicode_decode(proc.communicate()[0], encoding=encoding)
65 + status = proc.wait()
66 + if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK:
67 + output_lines = output.splitlines()
68 + if output_lines:
69 + version_split = output_lines[0].split('-')
70 + if len(version_split) > 1:
71 + VERSION = version_split[1]
72 + patchlevel = False
73 + if len(version_split) > 2:
74 + patchlevel = True
75 + VERSION = "%s_p%s" % (VERSION, version_split[2])
76 + if len(output_lines) > 1 and output_lines[1] == 'modified':
77 + head_timestamp = None
78 + if len(output_lines) > 3:
79 + try:
80 + head_timestamp = long(output_lines[3])
81 + except ValueError:
82 + pass
83 + timestamp = long(time.time())
84 + if head_timestamp is not None and timestamp > head_timestamp:
85 + timestamp = timestamp - head_timestamp
86 + if not patchlevel:
87 + VERSION = "%s_p0" % (VERSION,)
88 + VERSION = "%s_p%d" % (VERSION, timestamp)
89 + return VERSION
90 + else:
91 + print("NO output lines :(")
92 + VERSION = 'HEAD'
93 + return VERSION
94 + VERSION = _LazyVersion()
95 diff --git a/repoman/pym/repoman/main.py b/repoman/pym/repoman/main.py
96 index 2c9445a..825a82e 100755
97 --- a/repoman/pym/repoman/main.py
98 +++ b/repoman/pym/repoman/main.py
99 @@ -36,6 +36,7 @@ from repoman.repos import RepoSettings
100 from repoman.scanner import Scanner
101 from repoman import utilities
102 from repoman.modules.vcs.settings import VCSSettings
103 +from repoman import VERSION
104
105 if sys.hexversion >= 0x3000000:
106 basestring = str
107 @@ -62,7 +63,7 @@ def repoman_main(argv):
108 sys.argv, qahelp, repoman_settings.get("REPOMAN_DEFAULT_OPTS", ""))
109
110 if options.version:
111 - print("Repoman", portage.VERSION)
112 + print("Repoman", VERSION, "(portage-%s)" % portage.VERSION)
113 sys.exit(0)
114
115 logger = logging.getLogger()
116 --
117 2.9.3
118
119
120 --
121 Brian Dolbec <dolsen>

Replies