1 |
commit: 001dd58b705449b08acb34a085673a69b41b697e |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Sep 17 00:13:13 2015 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Sep 21 23:42:45 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=001dd58b |
7 |
|
8 |
repoman/main.py: Move some functions out of the main code definition |
9 |
|
10 |
Move gpgsign and need_signature to their own file: gpg.py |
11 |
Move sort_key() to the main body ahead of the main code. |
12 |
Add new file gpg.py |
13 |
|
14 |
pym/repoman/gpg.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
15 |
pym/repoman/main.py | 78 +++++----------------------------------------------- |
16 |
2 files changed, 86 insertions(+), 71 deletions(-) |
17 |
|
18 |
diff --git a/pym/repoman/gpg.py b/pym/repoman/gpg.py |
19 |
new file mode 100644 |
20 |
index 0000000..a6c4c5f |
21 |
--- /dev/null |
22 |
+++ b/pym/repoman/gpg.py |
23 |
@@ -0,0 +1,79 @@ |
24 |
+ |
25 |
+import errno |
26 |
+import logging |
27 |
+import subprocess |
28 |
+import sys |
29 |
+ |
30 |
+import portage |
31 |
+from portage import os |
32 |
+from portage import _encodings |
33 |
+from portage import _unicode_encode |
34 |
+from portage.exception import MissingParameter |
35 |
+from portage.process import find_binary |
36 |
+ |
37 |
+ |
38 |
+# Setup the GPG commands |
39 |
+def gpgsign(filename, repoman_settings, options): |
40 |
+ gpgcmd = repoman_settings.get("PORTAGE_GPG_SIGNING_COMMAND") |
41 |
+ if gpgcmd in [None, '']: |
42 |
+ raise MissingParameter("PORTAGE_GPG_SIGNING_COMMAND is unset!" |
43 |
+ " Is make.globals missing?") |
44 |
+ if "${PORTAGE_GPG_KEY}" in gpgcmd and \ |
45 |
+ "PORTAGE_GPG_KEY" not in repoman_settings: |
46 |
+ raise MissingParameter("PORTAGE_GPG_KEY is unset!") |
47 |
+ if "${PORTAGE_GPG_DIR}" in gpgcmd: |
48 |
+ if "PORTAGE_GPG_DIR" not in repoman_settings: |
49 |
+ repoman_settings["PORTAGE_GPG_DIR"] = \ |
50 |
+ os.path.expanduser("~/.gnupg") |
51 |
+ logging.info( |
52 |
+ "Automatically setting PORTAGE_GPG_DIR to '%s'" % |
53 |
+ repoman_settings["PORTAGE_GPG_DIR"]) |
54 |
+ else: |
55 |
+ repoman_settings["PORTAGE_GPG_DIR"] = \ |
56 |
+ os.path.expanduser(repoman_settings["PORTAGE_GPG_DIR"]) |
57 |
+ if not os.access(repoman_settings["PORTAGE_GPG_DIR"], os.X_OK): |
58 |
+ raise portage.exception.InvalidLocation( |
59 |
+ "Unable to access directory: PORTAGE_GPG_DIR='%s'" % |
60 |
+ repoman_settings["PORTAGE_GPG_DIR"]) |
61 |
+ gpgvars = {"FILE": filename} |
62 |
+ for k in ("PORTAGE_GPG_DIR", "PORTAGE_GPG_KEY"): |
63 |
+ v = repoman_settings.get(k) |
64 |
+ if v is not None: |
65 |
+ gpgvars[k] = v |
66 |
+ gpgcmd = portage.util.varexpand(gpgcmd, mydict=gpgvars) |
67 |
+ if options.pretend: |
68 |
+ print("(" + gpgcmd + ")") |
69 |
+ else: |
70 |
+ # Encode unicode manually for bug #310789. |
71 |
+ gpgcmd = portage.util.shlex_split(gpgcmd) |
72 |
+ |
73 |
+ if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \ |
74 |
+ not os.path.isabs(gpgcmd[0]): |
75 |
+ # Python 3.1 _execvp throws TypeError for non-absolute executable |
76 |
+ # path passed as bytes (see http://bugs.python.org/issue8513). |
77 |
+ fullname = find_binary(gpgcmd[0]) |
78 |
+ if fullname is None: |
79 |
+ raise portage.exception.CommandNotFound(gpgcmd[0]) |
80 |
+ gpgcmd[0] = fullname |
81 |
+ |
82 |
+ gpgcmd = [ |
83 |
+ _unicode_encode(arg, encoding=_encodings['fs'], errors='strict') |
84 |
+ for arg in gpgcmd] |
85 |
+ rValue = subprocess.call(gpgcmd) |
86 |
+ if rValue == os.EX_OK: |
87 |
+ os.rename(filename + ".asc", filename) |
88 |
+ else: |
89 |
+ raise portage.exception.PortageException( |
90 |
+ "!!! gpg exited with '" + str(rValue) + "' status") |
91 |
+ |
92 |
+def need_signature(filename): |
93 |
+ try: |
94 |
+ with open( |
95 |
+ _unicode_encode( |
96 |
+ filename, encoding=_encodings['fs'], errors='strict'), |
97 |
+ 'rb') as f: |
98 |
+ return b"BEGIN PGP SIGNED MESSAGE" not in f.readline() |
99 |
+ except IOError as e: |
100 |
+ if e.errno in (errno.ENOENT, errno.ESTALE): |
101 |
+ return False |
102 |
+ raise |
103 |
|
104 |
diff --git a/pym/repoman/main.py b/pym/repoman/main.py |
105 |
index 4dbc09e..e276aba 100755 |
106 |
--- a/pym/repoman/main.py |
107 |
+++ b/pym/repoman/main.py |
108 |
@@ -38,7 +38,6 @@ import portage.repository.config |
109 |
from portage import cvstree, normalize_path |
110 |
from portage import util |
111 |
from portage.dep import Atom |
112 |
-from portage.exception import MissingParameter |
113 |
from portage.process import find_binary, spawn |
114 |
from portage.output import ( |
115 |
bold, create_color_func, green, nocolor, red) |
116 |
@@ -67,6 +66,7 @@ from repoman.checks.ebuilds.variables.license import LicenseChecks |
117 |
from repoman.checks.ebuilds.variables.restrict import RestrictChecks |
118 |
from repoman.ebuild import Ebuild |
119 |
from repoman.errors import err |
120 |
+from repoman.gpg import gpgsign, need_signature |
121 |
from repoman.modules.commit import repochecks |
122 |
from repoman.profile import check_profiles, dev_keywords, setup_profile |
123 |
from repoman.qa_data import ( |
124 |
@@ -97,6 +97,11 @@ non_ascii_re = re.compile(r'[^\x00-\x7f]') |
125 |
|
126 |
# A sane umask is needed for files that portage creates. |
127 |
os.umask(0o22) |
128 |
+ |
129 |
+def sort_key(item): |
130 |
+ return item[2].sub_path |
131 |
+ |
132 |
+ |
133 |
# Repoman sets it's own ACCEPT_KEYWORDS and we don't want it to |
134 |
# behave incrementally. |
135 |
repoman_incrementals = tuple( |
136 |
@@ -673,9 +678,6 @@ for xpkg in effective_scanlist: |
137 |
relevant_profiles.extend( |
138 |
(keyword, groups, prof) for prof in profiles[arch]) |
139 |
|
140 |
- def sort_key(item): |
141 |
- return item[2].sub_path |
142 |
- |
143 |
relevant_profiles.sort(key=sort_key) |
144 |
|
145 |
for keyword, groups, prof in relevant_profiles: |
146 |
@@ -1441,72 +1443,6 @@ else: |
147 |
except OSError: |
148 |
pass |
149 |
|
150 |
- # Setup the GPG commands |
151 |
- def gpgsign(filename): |
152 |
- gpgcmd = repoman_settings.get("PORTAGE_GPG_SIGNING_COMMAND") |
153 |
- if gpgcmd in [None, '']: |
154 |
- raise MissingParameter("PORTAGE_GPG_SIGNING_COMMAND is unset!" |
155 |
- " Is make.globals missing?") |
156 |
- if "${PORTAGE_GPG_KEY}" in gpgcmd and \ |
157 |
- "PORTAGE_GPG_KEY" not in repoman_settings: |
158 |
- raise MissingParameter("PORTAGE_GPG_KEY is unset!") |
159 |
- if "${PORTAGE_GPG_DIR}" in gpgcmd: |
160 |
- if "PORTAGE_GPG_DIR" not in repoman_settings: |
161 |
- repoman_settings["PORTAGE_GPG_DIR"] = \ |
162 |
- os.path.expanduser("~/.gnupg") |
163 |
- logging.info( |
164 |
- "Automatically setting PORTAGE_GPG_DIR to '%s'" % |
165 |
- repoman_settings["PORTAGE_GPG_DIR"]) |
166 |
- else: |
167 |
- repoman_settings["PORTAGE_GPG_DIR"] = \ |
168 |
- os.path.expanduser(repoman_settings["PORTAGE_GPG_DIR"]) |
169 |
- if not os.access(repoman_settings["PORTAGE_GPG_DIR"], os.X_OK): |
170 |
- raise portage.exception.InvalidLocation( |
171 |
- "Unable to access directory: PORTAGE_GPG_DIR='%s'" % |
172 |
- repoman_settings["PORTAGE_GPG_DIR"]) |
173 |
- gpgvars = {"FILE": filename} |
174 |
- for k in ("PORTAGE_GPG_DIR", "PORTAGE_GPG_KEY"): |
175 |
- v = repoman_settings.get(k) |
176 |
- if v is not None: |
177 |
- gpgvars[k] = v |
178 |
- gpgcmd = portage.util.varexpand(gpgcmd, mydict=gpgvars) |
179 |
- if options.pretend: |
180 |
- print("(" + gpgcmd + ")") |
181 |
- else: |
182 |
- # Encode unicode manually for bug #310789. |
183 |
- gpgcmd = portage.util.shlex_split(gpgcmd) |
184 |
- |
185 |
- if sys.hexversion < 0x3020000 and sys.hexversion >= 0x3000000 and \ |
186 |
- not os.path.isabs(gpgcmd[0]): |
187 |
- # Python 3.1 _execvp throws TypeError for non-absolute executable |
188 |
- # path passed as bytes (see http://bugs.python.org/issue8513). |
189 |
- fullname = find_binary(gpgcmd[0]) |
190 |
- if fullname is None: |
191 |
- raise portage.exception.CommandNotFound(gpgcmd[0]) |
192 |
- gpgcmd[0] = fullname |
193 |
- |
194 |
- gpgcmd = [ |
195 |
- _unicode_encode(arg, encoding=_encodings['fs'], errors='strict') |
196 |
- for arg in gpgcmd] |
197 |
- rValue = subprocess.call(gpgcmd) |
198 |
- if rValue == os.EX_OK: |
199 |
- os.rename(filename + ".asc", filename) |
200 |
- else: |
201 |
- raise portage.exception.PortageException( |
202 |
- "!!! gpg exited with '" + str(rValue) + "' status") |
203 |
- |
204 |
- def need_signature(filename): |
205 |
- try: |
206 |
- with open( |
207 |
- _unicode_encode( |
208 |
- filename, encoding=_encodings['fs'], errors='strict'), |
209 |
- 'rb') as f: |
210 |
- return b"BEGIN PGP SIGNED MESSAGE" not in f.readline() |
211 |
- except IOError as e: |
212 |
- if e.errno in (errno.ENOENT, errno.ESTALE): |
213 |
- return False |
214 |
- raise |
215 |
- |
216 |
# When files are removed and re-added, the cvs server will put /Attic/ |
217 |
# inside the $Header path. This code detects the problem and corrects it |
218 |
# so that the Manifest will generate correctly. See bug #169500. |
219 |
@@ -1557,7 +1493,7 @@ else: |
220 |
manifest_path = os.path.join(repoman_settings["O"], "Manifest") |
221 |
if not need_signature(manifest_path): |
222 |
continue |
223 |
- gpgsign(manifest_path) |
224 |
+ gpgsign(manifest_path, repoman_settings, options) |
225 |
except portage.exception.PortageException as e: |
226 |
portage.writemsg("!!! %s\n" % str(e)) |
227 |
portage.writemsg("!!! Disabled FEATURES='sign'\n") |