]> git.decadent.org.uk Git - dak.git/blobdiff - dak/generate_packages_sources2.py
Merge remote-tracking branch 'jcristau/cs-set-log-suite'
[dak.git] / dak / generate_packages_sources2.py
index ff890377db47f2e8abea926cfa30b51a9d8de16a..51d8e9b8d8f894fdb832d113122e81c1c459c9c0 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 suite.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 suite.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 suite.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
@@ -67,24 +70,33 @@ SELECT
    WHERE s.id=sm.src_id
   )
   ||
+  CASE
+    WHEN src_associations_full.extra_source THEN E'\nExtra-Source-Only\: yes'
+    ELSE ''
+  END
+  ||
   E'\nDirectory\: pool/' || :component_name || '/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z')
   ||
-  E'\nPriority\: ' || pri.priority
+  E'\nPriority\: ' || COALESCE(pri.priority, 'extra')
   ||
-  E'\nSection\: ' || sec.section
+  E'\nSection\: ' || COALESCE(sec.section, 'misc')
 
 FROM
 
 source s
-JOIN src_associations sa ON s.id = sa.source
+JOIN src_associations_full ON src_associations_full.suite = :suite AND s.id = src_associations_full.source
 JOIN files f ON s.file=f.id
-JOIN override o ON o.package = s.source
-JOIN section sec ON o.section = sec.id
-JOIN priority pri ON o.priority = pri.id
-
-WHERE
-  sa.suite = :suite
-  AND o.suite = :overridesuite AND o.component = :component AND o.type = :dsc_type
+JOIN files_archive_map fam
+  ON fam.file_id = f.id
+     AND fam.archive_id = (SELECT archive_id FROM suite WHERE id = :suite)
+     AND fam.component_id = :component
+LEFT JOIN override o ON o.package = s.source
+                     AND o.suite = :overridesuite
+                     AND o.component = :component
+                     AND o.type = :dsc_type
+LEFT JOIN section sec ON o.section = sec.id
+LEFT JOIN priority pri ON o.priority = pri.id
+LEFT JOIN suite on suite.id = :suite
 
 ORDER BY
 s.source, s.version
@@ -104,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
@@ -137,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
@@ -174,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 suite.checksums && array['md5sum'] THEN E'\nMD5sum\: ' || tmp.md5sum ELSE '' END
+  || CASE WHEN suite.checksums && array['sha1'] THEN E'\nSHA1\: ' || tmp.sha1sum ELSE '' END
+  || CASE WHEN suite.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 ON suite.id = :suite
 
 WHERE
   (
@@ -196,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
 """
@@ -227,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,
@@ -290,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})
@@ -313,11 +357,11 @@ def main():
 
     Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
                  ('a','archive','Generate-Packages-Sources::Options::Archive','HasArg'),
-                 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
+                 ('s',"suite","Generate-Packages-Sources::Options::Suite",'HasArg'),
                  ('f',"force","Generate-Packages-Sources::Options::Force"),
                  ('o','option','','ArbItem')]
 
-    suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
+    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
     try:
         Options = cnf.subtree("Generate-Packages-Sources::Options")
     except KeyError:
@@ -338,6 +382,7 @@ def main():
 
     if Options.has_key("Suite"):
         suites = []
+        suite_names = Options['Suite'].split(',')
         for s in suite_names:
             suite = get_suite(s.lower(), session)
             if suite:
@@ -353,7 +398,6 @@ def main():
 
     force = Options.has_key("Force") and Options["Force"]
 
-    component_ids = [ c.component_id for c in session.query(Component).all() ]
 
     def parse_results(message):
         # Split out into (code, msg)
@@ -365,10 +409,15 @@ 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:
-            import utils
-            utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
+            import daklib.utils
+            daklib.utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
         for c in component_ids:
             pool.apply_async(generate_sources, [s.suite_id, c], callback=parse_results)
             if not s.include_long_description: