Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r10890 - in main/trunk: . pym/portage pym/portage/dbapi
Date: Wed, 02 Jul 2008 07:51:01
Message-Id: E1KDx79-0000M4-VQ@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-07-02 07:50:54 +0000 (Wed, 02 Jul 2008)
3 New Revision: 10890
4
5 Modified:
6 main/trunk/DEVELOPING
7 main/trunk/pym/portage/__init__.py
8 main/trunk/pym/portage/checksum.py
9 main/trunk/pym/portage/dbapi/porttree.py
10 main/trunk/pym/portage/dep.py
11 main/trunk/pym/portage/getbinpkg.py
12 main/trunk/pym/portage/gpg.py
13 main/trunk/pym/portage/locks.py
14 Log:
15 Py3k compatibility patch by Ali Polatel <hawking@g.o>.
16 Don't use the format raise Exception, "string"
17
18
19 Modified: main/trunk/DEVELOPING
20 ===================================================================
21 --- main/trunk/DEVELOPING 2008-07-02 06:45:00 UTC (rev 10889)
22 +++ main/trunk/DEVELOPING 2008-07-02 07:50:54 UTC (rev 10890)
23 @@ -94,6 +94,18 @@
24
25 The get call is nicer (compact) and faster (try,except are slow).
26
27 +Exceptions
28 +----------
29 +
30 +Don't use the format raise Exception, "string"
31 +It will be removed in py3k.
32 +
33 +YES:
34 + raise KeyError("No key")
35 +
36 +NO:
37 + raise KeyError, "No key"
38 +
39 Imports
40 -------
41
42
43 Modified: main/trunk/pym/portage/__init__.py
44 ===================================================================
45 --- main/trunk/pym/portage/__init__.py 2008-07-02 06:45:00 UTC (rev 10889)
46 +++ main/trunk/pym/portage/__init__.py 2008-07-02 07:50:54 UTC (rev 10890)
47 @@ -169,7 +169,7 @@
48 if EmptyOnError:
49 return ""
50 else:
51 - raise KeyError, "Key not found in list; '%s'" % key
52 + raise KeyError("Key not found in list; '%s'" % key)
53
54 def getcwd():
55 "this fixes situations where the current directory doesn't exist"
56 @@ -1804,14 +1804,14 @@
57
58 def modifying(self):
59 if self.locked:
60 - raise Exception, "Configuration is locked."
61 + raise Exception("Configuration is locked.")
62
63 def backup_changes(self,key=None):
64 self.modifying()
65 if key and key in self.configdict["env"]:
66 self.backupenv[key] = copy.deepcopy(self.configdict["env"][key])
67 else:
68 - raise KeyError, "No such key defined in environment: %s" % key
69 + raise KeyError("No such key defined in environment: %s" % key)
70
71 def reset(self,keeping_pkg=0,use_cache=1):
72 """
73
74 Modified: main/trunk/pym/portage/checksum.py
75 ===================================================================
76 --- main/trunk/pym/portage/checksum.py 2008-07-02 06:45:00 UTC (rev 10889)
77 +++ main/trunk/pym/portage/checksum.py 2008-07-02 07:50:54 UTC (rev 10890)
78 @@ -186,7 +186,10 @@
79 myhash = perform_checksum(filename, x, calc_prelink=calc_prelink)[0]
80 if mydict[x] != myhash:
81 if strict:
82 - raise portage.exception.DigestException, "Failed to verify '$(file)s' on checksum type '%(type)s'" % {"file":filename, "type":x}
83 + raise portage.exception.DigestException(
84 + ("Failed to verify '$(file)s' on " + \
85 + "checksum type '%(type)s'") % \
86 + {"file" : filename, "type" : x})
87 else:
88 file_is_ok = False
89 reason = (("Failed on %s verification" % x), myhash,mydict[x])
90
91 Modified: main/trunk/pym/portage/dbapi/porttree.py
92 ===================================================================
93 --- main/trunk/pym/portage/dbapi/porttree.py 2008-07-02 06:45:00 UTC (rev 10889)
94 +++ main/trunk/pym/portage/dbapi/porttree.py 2008-07-02 07:50:54 UTC (rev 10890)
95 @@ -263,11 +263,15 @@
96 elif self.manifestVerifier:
97 if not self.manifestVerifier.verify(myManifestPath):
98 # Verification failed the desired level.
99 - raise UntrustedSignature, "Untrusted Manifest: %(manifest)s" % {"manifest":myManifestPath}
100 + raise UntrustedSignature(
101 + "Untrusted Manifest: %(manifest)s" % \
102 + {"manifest" : myManifestPath})
103
104 if ("severe" in self.mysettings.features) and \
105 (mys != portage.gpg.fileStats(myManifestPath)):
106 - raise SecurityViolation, "Manifest changed: %(manifest)s" % {"manifest":myManifestPath}
107 + raise SecurityViolation(
108 + "Manifest changed: %(manifest)s" % \
109 + {"manifest":myManifestPath})
110
111 except InvalidSignature, e:
112 if ("strict" in self.mysettings.features) or \
113 @@ -284,7 +288,9 @@
114 except (OSError, FileNotFound), e:
115 if ("strict" in self.mysettings.features) or \
116 ("severe" in self.mysettings.features):
117 - raise SecurityViolation, "Error in verification of signatures: %(errormsg)s" % {"errormsg":str(e)}
118 + raise SecurityViolation(
119 + "Error in verification of signatures: " + \
120 + "%(errormsg)s" % {"errormsg" : str(e)})
121 writemsg("!!! Manifest is missing or inaccessable: %(manifest)s\n" % {"manifest":myManifestPath},
122 noiselevel=-1)
123
124
125 Modified: main/trunk/pym/portage/dep.py
126 ===================================================================
127 --- main/trunk/pym/portage/dep.py 2008-07-02 06:45:00 UTC (rev 10889)
128 +++ main/trunk/pym/portage/dep.py 2008-07-02 07:50:54 UTC (rev 10890)
129 @@ -246,7 +246,7 @@
130 if mydeparray:
131 newdeparray.append(mydeparray.pop(0))
132 else:
133 - raise ValueError, "Conditional with no target."
134 + raise ValueError("Conditional with no target.")
135
136 # Deprecation checks
137 warned = 0
138
139 Modified: main/trunk/pym/portage/getbinpkg.py
140 ===================================================================
141 --- main/trunk/pym/portage/getbinpkg.py 2008-07-02 06:45:00 UTC (rev 10889)
142 +++ main/trunk/pym/portage/getbinpkg.py 2008-07-02 07:50:54 UTC (rev 10890)
143 @@ -82,7 +82,8 @@
144
145 parts = baseurl.split("://",1)
146 if len(parts) != 2:
147 - raise ValueError, "Provided URL does not contain protocol identifier. '%s'" % baseurl
148 + raise ValueError("Provided URL does not " + \
149 + "contain protocol identifier. '%s'" % baseurl)
150 protocol,url_parts = parts
151 del parts
152
153 @@ -104,7 +105,7 @@
154 del userpass_host
155
156 if len(userpass) > 2:
157 - raise ValueError, "Unable to interpret username/password provided."
158 + raise ValueError("Unable to interpret username/password provided.")
159 elif len(userpass) == 2:
160 username = userpass[0]
161 password = userpass[1]
162 @@ -323,7 +324,7 @@
163 elif protocol == "sftp":
164 listing = conn.listdir(address)
165 else:
166 - raise TypeError, "Unknown protocol. '%s'" % protocol
167 + raise TypeError("Unknown protocol. '%s'" % protocol)
168
169 if not keepconnection:
170 conn.close()
171 @@ -355,7 +356,7 @@
172 finally:
173 f.close()
174 else:
175 - raise TypeError, "Unknown protocol. '%s'" % protocol
176 + raise TypeError("Unknown protocol. '%s'" % protocol)
177
178 if data:
179 xpaksize = portage.xpak.decodeint(data[-8:-4])
180 @@ -447,7 +448,7 @@
181 finally:
182 f.close()
183 else:
184 - raise TypeError, "Unknown protocol. '%s'" % protocol
185 + raise TypeError("Unknown protocol. '%s'" % protocol)
186
187 if not keepconnection:
188 conn.close()
189
190 Modified: main/trunk/pym/portage/gpg.py
191 ===================================================================
192 --- main/trunk/pym/portage/gpg.py 2008-07-02 06:45:00 UTC (rev 10889)
193 +++ main/trunk/pym/portage/gpg.py 2008-07-02 07:50:54 UTC (rev 10890)
194 @@ -10,6 +10,10 @@
195 import commands
196 import portage.exception
197 import portage.checksum
198 +from portage.exception import CommandNotFound, \
199 + DirectoryNotFound, FileNotFound, \
200 + InvalidData, InvalidDataType, InvalidSignature, MissingParameter, \
201 + MissingSignature, PortageException, SecurityViolation
202
203 GPG_BINARY = "/usr/bin/gpg"
204 GPG_OPTIONS = " --lock-never --no-random-seed-file --no-greeting --no-sig-cache "
205 @@ -42,34 +46,38 @@
206 if (keydir != None):
207 # Verify that the keydir is valid.
208 if type(keydir) != types.StringType:
209 - raise portage.exception.InvalidDataType, "keydir argument: %s" % keydir
210 + raise InvalidDataType(
211 + "keydir argument: %s" % keydir)
212 if not os.path.isdir(keydir):
213 - raise portage.exception.DirectoryNotFound, "keydir: %s" % keydir
214 + raise DirectoryNotFound("keydir: %s" % keydir)
215 self.keydir = copy.deepcopy(keydir)
216
217 if (keyring != None):
218 # Verify that the keyring is a valid filename and exists.
219 if type(keyring) != types.StringType:
220 - raise portage.exception.InvalidDataType, "keyring argument: %s" % keyring
221 + raise InvalidDataType("keyring argument: %s" % keyring)
222 if keyring.find("/") != -1:
223 - raise portage.exception.InvalidData, "keyring: %s" % keyring
224 + raise InvalidData("keyring: %s" % keyring)
225 pathname = ""
226 if keydir:
227 pathname = keydir + "/" + keyring
228 if not os.path.isfile(pathname):
229 - raise portage.exception.FileNotFound, "keyring missing: %s (dev.gentoo.org/~carpaski/gpg/)" % pathname
230 + raise FileNotFound(
231 + "keyring missing: %s (dev.gentoo.org/~carpaski/gpg/)" % \
232 + pathname)
233
234 keyringPath = keydir+"/"+keyring
235
236 if not keyring or not keyringPath and requireSignedRing:
237 - raise portage.exception.MissingParameter
238 + raise MissingParameter((keyring, keyringPath))
239
240 self.keyringStats = fileStats(keyringPath)
241 self.minimumTrust = TRUSTED
242 if not self.verify(keyringPath, keyringPath+".asc"):
243 self.keyringIsTrusted = False
244 if requireSignedRing:
245 - raise portage.exception.InvalidSignature, "Required keyring verification: "+keyringPath
246 + raise InvalidSignature(
247 + "Required keyring verification: " + keyringPath)
248 else:
249 self.keyringIsTrusted = True
250
251 @@ -81,27 +89,27 @@
252 if self.keyringStats and self.keyringPath:
253 new_stats = fileStats(self.keyringPath)
254 if new_stats != self.keyringStats:
255 - raise portage.exception.SecurityViolation, "GPG keyring changed!"
256 + raise SecurityViolation("GPG keyring changed!")
257
258 def verify(self, filename, sigfile=None):
259 """Uses minimumTrust to determine if it is Valid/True or Invalid/False"""
260 self._verifyKeyring()
261
262 if not os.path.isfile(filename):
263 - raise portage.exception.FileNotFound, filename
264 + raise FileNotFound, filename
265
266 if sigfile and not os.path.isfile(sigfile):
267 - raise portage.exception.FileNotFound, sigfile
268 + raise FileNotFound, sigfile
269
270 if self.keydir and not os.path.isdir(self.keydir):
271 - raise portage.exception.DirectoryNotFound, filename
272 + raise DirectoryNotFound, filename
273
274 if self.keyringPath:
275 if not os.path.isfile(self.keyringPath):
276 - raise portage.exception.FileNotFound, self.keyringPath
277 + raise FileNotFound, self.keyringPath
278
279 if not os.path.isfile(filename):
280 - raise portage.exception.CommandNotFound, filename
281 + raise CommandNotFound(filename)
282
283 command = GPG_BINARY + GPG_VERIFY_FLAGS + GPG_OPTIONS
284 if self.keydir:
285 @@ -119,7 +127,7 @@
286 result = (result >> 8)
287
288 if signal:
289 - raise SignalCaught, "Signal: %d" % (signal)
290 + raise PortageException("Signal: %d" % (signal))
291
292 trustLevel = UNTRUSTED
293 if result == 0:
294 @@ -127,22 +135,22 @@
295 #if portage.output.find("WARNING") != -1:
296 # trustLevel = MARGINAL
297 if portage.output.find("BAD") != -1:
298 - raise portage.exception.InvalidSignature, filename
299 + raise InvalidSignature(filename)
300 elif result == 1:
301 trustLevel = EXISTS
302 if portage.output.find("BAD") != -1:
303 - raise portage.exception.InvalidSignature, filename
304 + raise InvalidSignature(filename)
305 elif result == 2:
306 trustLevel = UNTRUSTED
307 if portage.output.find("could not be verified") != -1:
308 - raise portage.exception.MissingSignature, filename
309 + raise MissingSignature(filename)
310 if portage.output.find("public key not found") != -1:
311 if self.keyringIsTrusted: # We trust the ring, but not the key specifically.
312 trustLevel = MARGINAL
313 else:
314 - raise portage.exception.InvalidSignature, filename+" (Unknown Signature)"
315 + raise InvalidSignature(filename+"(Unknown Signature)")
316 else:
317 - raise portage.exception.UnknownCondition, "GPG returned unknown result: %d" % (result)
318 + raise PortageException("GPG returned unknown result: %d" % (result))
319
320 if trustLevel >= self.minimumTrust:
321 return True
322
323 Modified: main/trunk/pym/portage/locks.py
324 ===================================================================
325 --- main/trunk/pym/portage/locks.py 2008-07-02 06:45:00 UTC (rev 10889)
326 +++ main/trunk/pym/portage/locks.py 2008-07-02 07:50:54 UTC (rev 10890)
327 @@ -23,7 +23,7 @@
328 import fcntl
329
330 if not mypath:
331 - raise InvalidData, "Empty path given"
332 + raise InvalidData("Empty path given")
333
334 if type(mypath) == types.StringType and mypath[-1] == '/':
335 mypath = mypath[:-1]
336 @@ -44,7 +44,7 @@
337
338 if type(mypath) == types.StringType:
339 if not os.path.exists(os.path.dirname(mypath)):
340 - raise DirectoryNotFound, os.path.dirname(mypath)
341 + raise DirectoryNotFound(os.path.dirname(mypath))
342 if not os.path.exists(lockfilename):
343 old_mask=os.umask(000)
344 myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR,0660)
345 @@ -65,7 +65,8 @@
346 myfd = mypath
347
348 else:
349 - raise ValueError, "Unknown type passed in '%s': '%s'" % (type(mypath),mypath)
350 + raise ValueError("Unknown type passed in '%s': '%s'" % \
351 + (type(mypath), mypath))
352
353 # try for a non-blocking lock, if it's held, throw a message
354 # we're waiting on lockfile and use a blocking attempt.
355 @@ -165,7 +166,7 @@
356 except OSError:
357 if type(lockfilename) == types.StringType:
358 os.close(myfd)
359 - raise IOError, "Failed to unlock file '%s'\n" % lockfilename
360 + raise IOError("Failed to unlock file '%s'\n" % lockfilename)
361
362 try:
363 # This sleep call was added to allow other processes that are
364 @@ -230,7 +231,9 @@
365 os.close(myfd)
366
367 if not os.path.exists(myhardlock):
368 - raise FileNotFound, _("Created lockfile is missing: %(filename)s") % {"filename":myhardlock}
369 + raise FileNotFound(
370 + _("Created lockfile is missing: %(filename)s") % \
371 + {"filename" : myhardlock})
372
373 try:
374 res = os.link(myhardlock, lockfilename)
375
376 --
377 gentoo-commits@l.g.o mailing list