]> git.decadent.org.uk Git - dak.git/blobdiff - dak/examine_package.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / examine_package.py
index 56408f0ac2ed018775dcd3b841d9434fccaa42ed..edb9384b6c5be92b0e20ff23544ba1a031922ef4 100755 (executable)
@@ -61,9 +61,11 @@ import threading
 
 from daklib import utils
 from daklib.dbconn import DBConn, get_component_by_package_suite
+from daklib.gpg import SignedFile
 from daklib.regexes import html_escaping, re_html_escaping, re_version, re_spacestrip, \
                            re_contrib, re_nonfree, re_localhost, re_newlinespace, \
                            re_package, re_doc_directory
+from daklib.dak_exceptions import ChangesUnicodeError
 
 ################################################################################
 
@@ -338,7 +340,8 @@ def get_provides(suite):
                AND b.suite = (
                  SELECT id
                  FROM suite
-                 WHERE suite_name = '%(suite)s')''' % \
+                 WHERE suite_name = '%(suite)s'
+                 OR codename = '%(suite)s')''' % \
             {'suite': suite}
     for p in session.execute(query):
         for e in p:
@@ -504,7 +507,7 @@ def get_readme_source (dsc_filename):
 
     try:
         shutil.rmtree(tempdir)
-    except OSError, e:
+    except OSError as e:
         if errno.errorcode[e.errno] != 'EACCES':
             res += "%s: couldn't remove tmp dir %s for source tree." % (dsc_filename, tempdir)
 
@@ -557,30 +560,10 @@ def check_deb (suite, deb_filename, session = None):
 # Read a file, strip the signature and return the modified contents as
 # a string.
 def strip_pgp_signature (filename):
-    inputfile = utils.open_file (filename)
-    contents = ""
-    inside_signature = 0
-    skip_next = 0
-    for line in inputfile.readlines():
-        if line[:-1] == "":
-            continue
-        if inside_signature:
-            continue
-        if skip_next:
-            skip_next = 0
-            continue
-        if line.startswith("-----BEGIN PGP SIGNED MESSAGE"):
-            skip_next = 1
-            continue
-        if line.startswith("-----BEGIN PGP SIGNATURE"):
-            inside_signature = 1
-            continue
-        if line.startswith("-----END PGP SIGNATURE"):
-            inside_signature = 0
-            continue
-        contents += line
-    inputfile.close()
-    return contents
+    with utils.open_file(filename) as f:
+        data = f.read()
+        signedfile = SignedFile(data, keyrings=(), require_signature=False)
+        return signedfile.contents
 
 def display_changes(suite, changes_filename):
     global printed
@@ -651,7 +634,7 @@ def main ():
                     # Reset stdout here so future less invocations aren't FUBAR
                     less_fd.close()
                     sys.stdout = stdout_fd
-        except IOError, e:
+        except IOError as e:
             if errno.errorcode[e.errno] == 'EPIPE':
                 utils.warn("[examine-package] Caught EPIPE; skipping.")
                 pass