Coverage for dak/make_pkg_file_mapping.py: 95%
33 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-01-04 16:18 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-01-04 16:18 +0000
1#! /usr/bin/env python3
3"""
4Prints out, for every file in the pool, which source package and version it
5belongs to and for binary packages additionally which arch, binary package
6and binary package version it has in a standard rfc2822-like format.
8@contact: Debian FTP Master <ftpmaster@debian.org>
9@copyright: 2009 Peter Palfrader <peter@palfrader.org>
10@license: GNU General Public License version 2 or later
11"""
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28################################################################################
30# <arma> it's crypto -- think of it like magic if you like.
32################################################################################
34import sys
36from sqlalchemy import sql
38from daklib.dbconn import Archive, DBConn
40################################################################################
43def build_mapping(archive, session):
44 # The ORDER BY is in the queries so that compression of the output works
45 # better. It's the difference between a 9 megabyte bzip2 and a 2.5 mb
46 # bzip2 file.
48 query_sources = """
49 SELECT
50 source.source,
51 source.version,
52 './pool/' || component.name || '/' || files.filename AS path
53 FROM source
54 JOIN dsc_files ON source.id=dsc_files.source
55 JOIN files ON files.id=dsc_files.file
56 JOIN files_archive_map ON files.id = files_archive_map.file_id
57 JOIN component ON files_archive_map.component_id = component.id
58 JOIN files_archive_map fam_dsc ON fam_dsc.file_id=source.file AND fam_dsc.component_id=component.id AND fam_dsc.archive_id=files_archive_map.archive_id
59 WHERE files_archive_map.archive_id = :archive_id
60 ORDER BY source, version, component.id, files.filename
61 """
63 query_binaries = """
64 SELECT
65 source.source,
66 source.version,
67 architecture.arch_string AS arch,
68 './pool/' || component.name || '/' || files.filename AS path,
69 binaries.package,
70 binaries.version AS bin_version
71 FROM source
72 JOIN binaries ON source.id=binaries.source
73 JOIN files ON binaries.file=files.id
74 JOIN files_archive_map ON files.id = files_archive_map.file_id
75 JOIN component ON files_archive_map.component_id = component.id
76 JOIN architecture ON architecture.id=binaries.architecture
77 WHERE files_archive_map.archive_id = :archive_id
78 ORDER BY source, version, package, bin_version
79 """
81 for row in session.execute(
82 sql.text(query_sources), {"archive_id": archive.archive_id}
83 ).fetchall():
84 (source, version, path) = row
85 print("Path: %s" % path)
86 print("Source: %s" % source)
87 print("Source-Version: %s" % version)
88 print()
90 for row in session.execute(
91 sql.text(query_binaries), {"archive_id": archive.archive_id}
92 ).fetchall():
93 (source, version, arch, path, bin, binv) = row
94 print("Path: %s" % path)
95 print("Source: %s" % source)
96 print("Source-Version: %s" % version)
97 print("Architecture: %s" % arch)
98 print("Binary: %s" % bin)
99 print("Binary-Version: %s" % binv)
100 print()
103################################################################################
106def usage(status=0):
107 print("usage: dak make-pkg-file-mapping <archive>")
108 sys.exit(status)
111################################################################################
114def main():
115 if len(sys.argv) != 2: 115 ↛ 116line 115 didn't jump to line 116 because the condition on line 115 was never true
116 usage(1)
117 elif sys.argv[1] in ("-h", "--help"):
118 usage(0)
120 archive_name = sys.argv[1]
122 session = DBConn().session()
123 archive = session.query(Archive).filter_by(archive_name=archive_name).one()
124 build_mapping(archive, session)
127#########################################################################################
130if __name__ == "__main__":
131 main()
134# vim:set et:
135# vim:set ts=4:
136# vim:set shiftwidth=4: