From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 654A81387B1 for ; Mon, 21 Sep 2015 23:48:03 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id ABBAF21C03B; Mon, 21 Sep 2015 23:48:00 +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 D060021C012 for ; Mon, 21 Sep 2015 23:47:59 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 062B7340821 for ; Mon, 21 Sep 2015 23:47:59 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DAE2B23C for ; Mon, 21 Sep 2015 23:47:55 +0000 (UTC) From: "Brian Dolbec" 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" Message-ID: <1442878965.001dd58b705449b08acb34a085673a69b41b697e.dolsen@gentoo> Subject: [gentoo-commits] proj/portage:repoman commit in: pym/repoman/ X-VCS-Repository: proj/portage X-VCS-Files: pym/repoman/gpg.py pym/repoman/main.py X-VCS-Directories: pym/repoman/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 001dd58b705449b08acb34a085673a69b41b697e X-VCS-Branch: repoman Date: Mon, 21 Sep 2015 23:47:55 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2c7df114-314a-4225-a17f-dbbf4ef58198 X-Archives-Hash: 557c6355b01a861076692a063fcf254e Message-ID: <20150921234755.4f8-SkP8wLIo2-88kqyjSWkLLor75-sDIOnCqtr3cas@z> commit: 001dd58b705449b08acb34a085673a69b41b697e Author: Brian Dolbec gentoo org> AuthorDate: Thu Sep 17 00:13:13 2015 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Mon Sep 21 23:42:45 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=001dd58b 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. Add new file gpg.py pym/repoman/gpg.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ pym/repoman/main.py | 78 +++++----------------------------------------------- 2 files changed, 86 insertions(+), 71 deletions(-) diff --git a/pym/repoman/gpg.py b/pym/repoman/gpg.py new file mode 100644 index 0000000..a6c4c5f --- /dev/null +++ b/pym/repoman/gpg.py @@ -0,0 +1,79 @@ + +import errno +import logging +import subprocess +import sys + +import portage +from portage import os +from portage import _encodings +from portage import _unicode_encode +from portage.exception import MissingParameter +from portage.process import find_binary + + +# Setup the GPG commands +def gpgsign(filename, repoman_settings, options): + 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 diff --git a/pym/repoman/main.py b/pym/repoman/main.py index 4dbc09e..e276aba 100755 --- a/pym/repoman/main.py +++ b/pym/repoman/main.py @@ -38,7 +38,6 @@ import portage.repository.config from portage import cvstree, normalize_path from portage import util from portage.dep import Atom -from portage.exception import MissingParameter from portage.process import find_binary, spawn from portage.output import ( bold, create_color_func, green, nocolor, red) @@ -67,6 +66,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 +97,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 +678,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 +1443,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 +1493,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")