From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-834623-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id E6AAB1393F1
	for <garchives@archives.gentoo.org>; Thu, 17 Sep 2015 02:45:16 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 0543B21C033;
	Thu, 17 Sep 2015 02:45:16 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 7B43921C029
	for <gentoo-commits@lists.gentoo.org>; Thu, 17 Sep 2015 02:45:15 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 34747340A76
	for <gentoo-commits@lists.gentoo.org>; Thu, 17 Sep 2015 02:45:14 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id BCF0818C
	for <gentoo-commits@lists.gentoo.org>; Thu, 17 Sep 2015 02:45:11 +0000 (UTC)
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" <dolsen@gentoo.org>
Message-ID: <1442448793.aa5af88d23d5495e2541383a0a8ed9397d94d25a.dolsen@gentoo>
Subject: [gentoo-commits] proj/portage:repoman commit in: pym/repoman/
X-VCS-Repository: proj/portage
X-VCS-Files: pym/repoman/main.py
X-VCS-Directories: pym/repoman/
X-VCS-Committer: dolsen
X-VCS-Committer-Name: Brian Dolbec
X-VCS-Revision: aa5af88d23d5495e2541383a0a8ed9397d94d25a
X-VCS-Branch: repoman
Date: Thu, 17 Sep 2015 02:45:11 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 2ca5ce56-3c2d-4ee4-b6c1-520e4cceb6ff
X-Archives-Hash: 0298d20178dec651fc8cab77f7e82d35

commit:     aa5af88d23d5495e2541383a0a8ed9397d94d25a
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 17 00:13:13 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 00:13:13 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=aa5af88d

repoman/main.py: Move some functions out of the main code definition

Move gpgsign and need_signature to their own file: gpg.py
Move sort_key() to the main body ahead of the main code.

Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/repoman/main.py | 77 +++++------------------------------------------------
 1 file changed, 7 insertions(+), 70 deletions(-)

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 7887a79..843154c 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -67,6 +67,7 @@ from repoman.checks.ebuilds.variables.license import LicenseChecks
 from repoman.checks.ebuilds.variables.restrict import RestrictChecks
 from repoman.ebuild import Ebuild
 from repoman.errors import err
+from repoman.gpg import gpgsign, need_signature
 from repoman.modules.commit import repochecks
 from repoman.profile import check_profiles, dev_keywords, setup_profile
 from repoman.qa_data import (
@@ -97,6 +98,11 @@ non_ascii_re = re.compile(r'[^\x00-\x7f]')
 
 # A sane umask is needed for files that portage creates.
 os.umask(0o22)
+
+def sort_key(item):
+	return item[2].sub_path
+
+
 # Repoman sets it's own ACCEPT_KEYWORDS and we don't want it to
 # behave incrementally.
 repoman_incrementals = tuple(
@@ -673,9 +679,6 @@ for xpkg in effective_scanlist:
 			relevant_profiles.extend(
 				(keyword, groups, prof) for prof in profiles[arch])
 
-		def sort_key(item):
-			return item[2].sub_path
-
 		relevant_profiles.sort(key=sort_key)
 
 		for keyword, groups, prof in relevant_profiles:
@@ -1441,72 +1444,6 @@ else:
 			except OSError:
 				pass
 
-	# Setup the GPG commands
-	def gpgsign(filename):
-		gpgcmd = repoman_settings.get("PORTAGE_GPG_SIGNING_COMMAND")
-		if gpgcmd in [None, '']:
-			raise MissingParameter("PORTAGE_GPG_SIGNING_COMMAND is unset!"
-				" Is make.globals missing?")
-		if "${PORTAGE_GPG_KEY}" in gpgcmd and \
-			"PORTAGE_GPG_KEY" not in repoman_settings:
-			raise MissingParameter("PORTAGE_GPG_KEY is unset!")
-		if "${PORTAGE_GPG_DIR}" in gpgcmd:
-			if "PORTAGE_GPG_DIR" not in repoman_settings:
-				repoman_settings["PORTAGE_GPG_DIR"] = \
-					os.path.expanduser("~/.gnupg")
-				logging.info(
-					"Automatically setting PORTAGE_GPG_DIR to '%s'" %
-					repoman_settings["PORTAGE_GPG_DIR"])
-			else:
-				repoman_settings["PORTAGE_GPG_DIR"] = \
-					os.path.expanduser(repoman_settings["PORTAGE_GPG_DIR"])
-			if not os.access(repoman_settings["PORTAGE_GPG_DIR"], os.X_OK):
-				raise portage.exception.InvalidLocation(
-					"Unable to access directory: PORTAGE_GPG_DIR='%s'" %
-					repoman_settings["PORTAGE_GPG_DIR"])
-		gpgvars = {"FILE": filename}
-		for k in ("PORTAGE_GPG_DIR", "PORTAGE_GPG_KEY"):
-			v = repoman_settings.get(k)
-			if v is not None:
-				gpgvars[k] = v
-		gpgcmd = portage.util.varexpand(gpgcmd, mydict=gpgvars)
-		if options.pretend:
-			print("(" + gpgcmd + ")")
-		else:
-			# Encode unicode manually for bug #310789.
-			gpgcmd = portage.util.shlex_split(gpgcmd)
-
-			if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \
-				not os.path.isabs(gpgcmd[0]):
-				# Python 3.1 _execvp throws TypeError for non-absolute executable
-				# path passed as bytes (see http://bugs.python.org/issue8513).
-				fullname = find_binary(gpgcmd[0])
-				if fullname is None:
-					raise portage.exception.CommandNotFound(gpgcmd[0])
-				gpgcmd[0] = fullname
-
-			gpgcmd = [
-				_unicode_encode(arg, encoding=_encodings['fs'], errors='strict')
-				for arg in gpgcmd]
-			rValue = subprocess.call(gpgcmd)
-			if rValue == os.EX_OK:
-				os.rename(filename + ".asc", filename)
-			else:
-				raise portage.exception.PortageException(
-					"!!! gpg exited with '" + str(rValue) + "' status")
-
-	def need_signature(filename):
-		try:
-			with open(
-				_unicode_encode(
-					filename, encoding=_encodings['fs'], errors='strict'),
-				'rb') as f:
-				return b"BEGIN PGP SIGNED MESSAGE" not in f.readline()
-		except IOError as e:
-			if e.errno in (errno.ENOENT, errno.ESTALE):
-				return False
-			raise
-
 	# When files are removed and re-added, the cvs server will put /Attic/
 	# inside the $Header path. This code detects the problem and corrects it
 	# so that the Manifest will generate correctly. See bug #169500.
@@ -1557,7 +1494,7 @@ else:
 				manifest_path = os.path.join(repoman_settings["O"], "Manifest")
 				if not need_signature(manifest_path):
 					continue
-				gpgsign(manifest_path)
+				gpgsign(manifest_path, repoman_settings, options)
 		except portage.exception.PortageException as e:
 			portage.writemsg("!!! %s\n" % str(e))
 			portage.writemsg("!!! Disabled FEATURES='sign'\n")