]> git.decadent.org.uk Git - dak.git/blobdiff - dak/check_archive.py
Add missing checksums for source packages.
[dak.git] / dak / check_archive.py
index 53db5ba7256aee3453f3f8ae0f8f6cb80e6b68d2..3e537d805c1073d811c9ac9a1edbc1ed6a24885b 100755 (executable)
@@ -41,6 +41,7 @@ import apt_inst
 from daklib.dbconn import *
 from daklib import utils
 from daklib.config import Config
+from daklib.dak_exceptions import InvalidDscError, ChangesUnicodeError, CantOpenError
 
 ################################################################################
 
@@ -71,6 +72,7 @@ The following MODEs are available:
   validate-indices   - ensure files mentioned in Packages & Sources exist
   files-not-symlinks - check files in the database aren't symlinks
   validate-builddeps - validate build-dependencies of .dsc files in the archive
+  add-missing-source-checksums - add missing checksums for source packages
 """
     sys.exit(exit_code)
 
@@ -150,16 +152,22 @@ def check_dscs():
 
     count = 0
 
-    for dsc_file in DBConn().session().query(DSCFile):
-        f = dsc_file.poolfile.fullpath
+    for src in DBConn().session().query(DBSource).order_by(DBSource.source, DBSource.version):
+        f = src.poolfile.fullpath
         try:
             utils.parse_changes(f, signing_rules=1, dsc_file=1)
-        except InvalidDscError, line:
+        except InvalidDscError:
             utils.warn("syntax error in .dsc file %s" % f)
             count += 1
         except ChangesUnicodeError:
             utils.warn("found invalid dsc file (%s), not properly utf-8 encoded" % f)
             count += 1
+        except CantOpenError:
+            utils.warn("missing dsc file (%s)" % f)
+            count += 1
+        except Exception as e:
+            utils.warn("miscellaneous error parsing dsc file (%s): %s" % (f, str(e)))
+            count += 1
 
     if count:
         utils.warn("Found %s invalid .dsc files." % (count))
@@ -417,7 +425,7 @@ def check_indices_files_exist():
     Ensure files mentioned in Packages & Sources exist
     """
     for suite in [ "stable", "testing", "unstable" ]:
-        for component in Cnf.ValueList("Suite::%s::Components" % (suite)):
+        for component in get_component_names():
             architectures = get_suite_architectures(suite)
             for arch in [ i.arch_string.lower() for i in architectures ]:
                 if arch == "source":
@@ -471,6 +479,17 @@ def check_build_depends():
 
 ################################################################################
 
+def add_missing_source_checksums():
+    """ Add missing source checksums to source_metadata """
+    session = DBConn().session()
+    for checksum in ['Files', 'Checksums-Sha1', 'Checksums-Sha256']:
+        rows = session.execute('SELECT source_metadata_add_missing_checksum(:type)', {'type': checksum}).scalar()
+        if rows > 0:
+            print "Added {0} missing entries for {1}".format(rows, checksum)
+    session.commit()
+
+################################################################################
+
 def main ():
     global db_files, waste, excluded
 
@@ -518,6 +537,8 @@ def main ():
         check_files_not_symlinks()
     elif mode == "validate-builddeps":
         check_build_depends()
+    elif mode == "add-missing-source-checksums":
+        add_missing_source_checksums()
     else:
         utils.warn("unknown mode '%s'" % (mode))
         usage(1)