]> git.decadent.org.uk Git - dak.git/blobdiff - dak/generate_packages_sources2.py
Only generate binary checksum fields for the requested ones
[dak.git] / dak / generate_packages_sources2.py
index 3b58217a271df20671af2d9cf949cacbb097e64b..84983e1667dc12db06ff45ceed7a4eff15f43e66 100755 (executable)
@@ -56,9 +56,12 @@ SELECT
      STRING_AGG(
        CASE
          WHEN key = 'Source' THEN E'Package\: '
-         WHEN key = 'Files' THEN E'Files\:\n ' || f.md5sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
-         WHEN key = 'Checksums-Sha1' THEN E'Checksums-Sha1\:\n ' || f.sha1sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
-         WHEN key = 'Checksums-Sha256' THEN E'Checksums-Sha256\:\n ' || f.sha256sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
+         WHEN key = 'Files' AND sui.checksums && array['md5sum'] THEN E'Files\:\n ' || f.md5sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
+         WHEN key = 'Files' THEN NULL
+         WHEN key = 'Checksums-Sha1' AND sui.checksums && array['sha1'] THEN E'Checksums-Sha1\:\n ' || f.sha1sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
+         WHEN key = 'Checksums-Sha1' THEN NULL
+         WHEN key = 'Checksums-Sha256' AND sui.checksums && array['sha256'] THEN E'Checksums-Sha256\:\n ' || f.sha256sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
+         WHEN key = 'Checksums-Sha256' THEN NULL
          ELSE key || E'\: '
        END || value, E'\n' ORDER BY mk.ordering, mk.key)
    FROM
@@ -93,9 +96,7 @@ LEFT JOIN override o ON o.package = s.source
                      AND o.type = :dsc_type
 LEFT JOIN section sec ON o.section = sec.id
 LEFT JOIN priority pri ON o.priority = pri.id
-
-WHERE
-  (src_associations_full.extra_source OR o.suite IS NOT NULL)
+LEFT JOIN suite sui on sui.id = :suite
 
 ORDER BY
 s.source, s.version
@@ -115,7 +116,14 @@ def generate_sources(suite_id, component_id):
 
     overridesuite_id = suite.get_overridesuite().suite_id
 
-    writer = SourcesFileWriter(archive=suite.archive.path, suite=suite.suite_name, component=component.component_name)
+    writer_args = {
+            'archive': suite.archive.path,
+            'suite': suite.suite_name,
+            'component': component.component_name
+    }
+    if suite.indices_compression is not None:
+        writer_args['compression'] = suite.indices_compression
+    writer = SourcesFileWriter(**writer_args)
     output = writer.open()
 
     # run query and write Sources
@@ -148,7 +156,15 @@ WITH
       f.size AS size,
       f.md5sum AS md5sum,
       f.sha1sum AS sha1sum,
-      f.sha256sum AS sha256sum
+      f.sha256sum AS sha256sum,
+      (SELECT value FROM binaries_metadata
+        WHERE bin_id = b.id
+          AND key_id = (SELECT key_id FROM metadata_keys WHERE key = 'Priority'))
+       AS fallback_priority,
+      (SELECT value FROM binaries_metadata
+        WHERE bin_id = b.id
+          AND key_id = (SELECT key_id FROM metadata_keys WHERE key = 'Section'))
+       AS fallback_section
     FROM
       binaries b
       JOIN bin_associations ba ON b.id = ba.bin
@@ -185,19 +201,23 @@ SELECT
      eo.package = tmp.package
      AND eo.suite = :overridesuite AND eo.component = :component
   ), '')
-  || E'\nSection\: ' || sec.section
-  || E'\nPriority\: ' || pri.priority
+  || E'\nSection\: ' || COALESCE(sec.section, tmp.fallback_section)
+  || E'\nPriority\: ' || COALESCE(pri.priority, tmp.fallback_priority)
   || E'\nFilename\: pool/' || :component_name || '/' || tmp.filename
   || E'\nSize\: ' || tmp.size
-  || E'\nMD5sum\: ' || tmp.md5sum
-  || E'\nSHA1\: ' || tmp.sha1sum
-  || E'\nSHA256\: ' || tmp.sha256sum
+  || CASE WHEN sui.checksums && array['md5sum'] THEN E'\nMD5sum\: ' || tmp.md5sum ELSE '' END
+  || CASE WHEN sui.checksums && array['sha1'] THEN E'\nSHA1\: ' || tmp.sha1sum ELSE '' END
+  || CASE WHEN sui.checksums && array['sha256'] THEN E'\nSHA256\: ' || tmp.sha256sum ELSE '' END
 
 FROM
   tmp
-  JOIN override o ON o.package = tmp.package
-  JOIN section sec ON sec.id = o.section
-  JOIN priority pri ON pri.id = o.priority
+  LEFT JOIN override o ON o.package = tmp.package
+                      AND o.type = :type_id
+                      AND o.suite = :overridesuite
+                      AND o.component = :component
+  LEFT JOIN section sec ON sec.id = o.section
+  LEFT JOIN priority pri ON pri.id = o.priority
+  LEFT JOIN suite sui ON suite.id = :suite
 
 WHERE
   (
@@ -207,8 +227,6 @@ WHERE
     OR
       (architecture = :arch_all AND source NOT IN (SELECT DISTINCT source FROM tmp WHERE architecture <> :arch_all))
   )
-  AND
-    o.type = :type_id AND o.suite = :overridesuite AND o.component = :component
 
 ORDER BY tmp.source, tmp.package, tmp.version
 """
@@ -238,9 +256,16 @@ def generate_packages(suite_id, component_id, architecture_id, type_name):
     if include_long_description:
         metadata_skip.append("Description-md5")
 
-    writer = PackagesFileWriter(archive=suite.archive.path, suite=suite.suite_name,
-            component=component.component_name,
-            architecture=architecture.arch_string, debtype=type_name)
+    writer_args = {
+            'archive': suite.archive.path,
+            'suite': suite.suite_name,
+            'component': component.component_name,
+            'architecture': architecture.arch_string,
+            'debtype': type_name
+    }
+    if suite.indices_compression is not None:
+        writer_args['compression'] = suite.indices_compression
+    writer = PackagesFileWriter(**writer_args)
     output = writer.open()
 
     r = session.execute(_packages_query, {"archive_id": suite.archive.archive_id,
@@ -301,7 +326,15 @@ def generate_translations(suite_id, component_id):
     suite = session.query(Suite).get(suite_id)
     component = session.query(Component).get(component_id)
 
-    writer = TranslationFileWriter(archive=suite.archive.path, suite=suite.suite_name, component=component.component_name, language="en")
+    writer_args = {
+            'archive': suite.archive.path,
+            'suite': suite.suite_name,
+            'component': component.component_name,
+            'language': 'en',
+    }
+    if suite.i18n_compression is not None:
+        writer_args['compression'] = suite.i18n_compression
+    writer = TranslationFileWriter(**writer_args)
     output = writer.open()
 
     r = session.execute(_translations_query, {"suite": suite_id, "component": component_id})
@@ -375,6 +408,10 @@ def main():
         else:
             logger.log(['E: ', msg])
 
+    # Lock tables so that nobody can change things underneath us
+    session.execute("LOCK TABLE src_associations IN SHARE MODE")
+    session.execute("LOCK TABLE bin_associations IN SHARE MODE")
+
     for s in suites:
         component_ids = [ c.component_id for c in s.components ]
         if s.untouchable and not force: