public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: repoman/pym/repoman/
Date: Tue,  6 Dec 2016 03:54:30 +0000 (UTC)	[thread overview]
Message-ID: <1480970121.006b168c1bb6f5b6706a3af42e53764cffafd610.dolsen@gentoo> (raw)

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()


             reply	other threads:[~2016-12-06  3:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06  3:54 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-03-30 17:23 [gentoo-commits] proj/portage:master commit in: repoman/pym/repoman/ Zac Medico
2018-02-27 19:07 Michał Górny
2018-02-27 19:07 Michał Górny
2017-08-06  6:54 Michał Górny
2017-07-18 23:08 Brian Dolbec
2017-03-15 21:56 Brian Dolbec
2017-03-01 19:22 Brian Dolbec
2017-03-01 18:40 Brian Dolbec
2017-01-14 19:10 Mike Gilbert
2017-01-14 14:23 Mike Gilbert
2017-01-13 17:13 Zac Medico
2017-01-06 17:17 Brian Dolbec
2017-01-06 17:17 Brian Dolbec
2017-01-06 17:17 Brian Dolbec
2016-10-11 18:54 Brian Dolbec
2016-09-15 18:46 Brian Dolbec
2016-09-15 18:46 Brian Dolbec
2016-06-30  5:54 Michał Górny
2016-06-28 15:34 Mike Frysinger
2016-06-24  6:38 Zac Medico
2016-05-15 23:51 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480970121.006b168c1bb6f5b6706a3af42e53764cffafd610.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox