commit: 006b168c1bb6f5b6706a3af42e53764cffafd610
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 5 19:27:15 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Dec 5 20:35:21 2016 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=006b168c
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..780b611 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()