X-Git-Url: https://git.decadent.org.uk/gitweb/?p=dak.git;a=blobdiff_plain;f=dak%2Fgenerate_packages_sources2.py;h=51d8e9b8d8f894fdb832d113122e81c1c459c9c0;hp=8b4773d8528152f4b6c32a19a38730eb4ae8eba4;hb=026bdb9580e6d18bf504d2f44d46890df5d89f1a;hpb=190333466b6e57c4cfaa57c1e22ae366ce9d9dad diff --git a/dak/generate_packages_sources2.py b/dak/generate_packages_sources2.py index 8b4773d8..51d8e9b8 100755 --- a/dak/generate_packages_sources2.py +++ b/dak/generate_packages_sources2.py @@ -34,6 +34,7 @@ def usage(): print """Usage: dak generate-packages-sources2 [OPTIONS] Generate the Packages/Sources files + -a, --archive=ARCHIVE process suites in ARCHIVE -s, --suite=SUITE process this suite Default: All suites not marked 'untouchable' -f, --force Allow processing of untouchable suites @@ -55,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 @@ -66,24 +70,33 @@ SELECT WHERE s.id=sm.src_id ) || - E'\nDirectory\: pool/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z') + CASE + WHEN src_associations_full.extra_source THEN E'\nExtra-Source-Only\: yes' + ELSE '' + END || - E'\nPriority\: ' || pri.priority + E'\nDirectory\: pool/' || :component_name || '/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z') || - E'\nSection\: ' || sec.section + E'\nPriority\: ' || COALESCE(pri.priority, 'extra') + || + 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,6 +117,7 @@ def generate_sources(suite_id, component_id): overridesuite_id = suite.get_overridesuite().suite_id writer_args = { + 'archive': suite.archive.path, 'suite': suite.suite_name, 'component': component.component_name } @@ -113,7 +127,7 @@ def generate_sources(suite_id, component_id): output = writer.open() # run query and write Sources - r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "dsc_type": dsc_type, "overridesuite": overridesuite_id}) + r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "component_name": component.component_name, "dsc_type": dsc_type, "overridesuite": overridesuite_id}) for (stanza,) in r: print >>output, stanza print >>output, "" @@ -142,17 +156,25 @@ 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 JOIN files f ON f.id = b.file - JOIN location l ON l.id = f.location + JOIN files_archive_map fam ON f.id = fam.file_id AND fam.archive_id = :archive_id JOIN source s ON b.source = s.id WHERE (b.architecture = :arch_all OR b.architecture = :arch) AND b.type = :type_name AND ba.suite = :suite - AND l.component = :component + AND fam.component_id = :component ) SELECT @@ -179,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'\nFilename\: pool/' || tmp.filename + || 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 ( @@ -201,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 """ @@ -233,6 +257,7 @@ def generate_packages(suite_id, component_id, architecture_id, type_name): metadata_skip.append("Description-md5") writer_args = { + 'archive': suite.archive.path, 'suite': suite.suite_name, 'component': component.component_name, 'architecture': architecture.arch_string, @@ -243,7 +268,8 @@ def generate_packages(suite_id, component_id, architecture_id, type_name): writer = PackagesFileWriter(**writer_args) output = writer.open() - r = session.execute(_packages_query, {"suite": suite_id, "component": component_id, + r = session.execute(_packages_query, {"archive_id": suite.archive.archive_id, + "suite": suite_id, "component": component_id, 'component_name': component.component_name, "arch": architecture_id, "type_id": type_id, "type_name": type_name, "arch_all": arch_all_id, "overridesuite": overridesuite_id, "metadata_skip": metadata_skip, "include_long_description": 'true' if include_long_description else 'false'}) @@ -301,6 +327,7 @@ def generate_translations(suite_id, component_id): component = session.query(Component).get(component_id) writer_args = { + 'archive': suite.archive.path, 'suite': suite.suite_name, 'component': component.component_name, 'language': 'en', @@ -329,11 +356,12 @@ def main(): cnf = Config() Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"), - ('s',"suite","Generate-Packages-Sources::Options::Suite"), + ('a','archive','Generate-Packages-Sources::Options::Archive','HasArg'), + ('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: @@ -347,13 +375,14 @@ def main(): logger = daklog.Logger('generate-packages-sources2') - from daklib.dbconn import Component, DBConn, get_suite, Suite + from daklib.dbconn import Component, DBConn, get_suite, Suite, Archive session = DBConn().session() session.execute("SELECT add_missing_description_md5()") session.commit() if Options.has_key("Suite"): suites = [] + suite_names = Options['Suite'].split(',') for s in suite_names: suite = get_suite(s.lower(), session) if suite: @@ -362,11 +391,13 @@ def main(): print "I: Cannot find suite %s" % s logger.log(['Cannot find suite %s' % s]) else: - suites = session.query(Suite).filter(Suite.untouchable == False).all() + query = session.query(Suite).filter(Suite.untouchable == False) + if 'Archive' in Options: + query = query.join(Suite.archive).filter(Archive.archive_name==Options['Archive']) + suites = query.all() 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) @@ -378,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: