]> git.donarmstrong.com Git - dak.git/blob - dak/make_pkg_file_mapping.py
Remove old (and slow) code
[dak.git] / dak / make_pkg_file_mapping.py
1 #!/usr/bin/env python
2
3 """
4 Prints out, for every file in the pool, which source package and version it
5 belongs to and for binary packages additionally which arch, binary package
6 and binary package version it has in a standard rfc2822-like format.
7
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 """
12
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
26
27
28 ################################################################################
29
30 # <arma> it's crypto -- think of it like magic if you like.
31
32 ################################################################################
33
34 import sys
35
36 from daklib.dbconn import *
37
38 ################################################################################
39
40 def build_mapping(archive, session):
41     # The ORDER BY is in the queries so that compression of the output works
42     # better.  It's the difference between a 9 megabyte bzip2 and a 2.5 mb
43     # bzip2 file.
44
45     query_sources = """
46     SELECT
47         source.source,
48         source.version,
49         './pool/' || component.name || '/' || files.filename AS path
50     FROM source
51       JOIN dsc_files ON source.id=dsc_files.source
52       JOIN files ON files.id=dsc_files.file
53       JOIN files_archive_map ON files.id = files_archive_map.file_id
54       JOIN component ON files_archive_map.component_id = component.id
55     WHERE files_archive_map.archive_id = :archive_id
56     ORDER BY source, version
57     """
58
59     query_binaries = """
60     SELECT
61         source.source,
62         source.version,
63         architecture.arch_string AS arch,
64         './pool/' || component.name || '/' || files.filename AS path,
65         binaries.package,
66         binaries.version AS bin_version
67     FROM source
68       JOIN binaries ON source.id=binaries.source
69       JOIN files ON binaries.file=files.id
70       JOIN files_archive_map ON files.id = files_archive_map.file_id
71       JOIN component ON files_archive_map.component_id = component.id
72       JOIN architecture ON architecture.id=binaries.architecture
73     WHERE files_archive_map.archive_id = :archive_id
74     ORDER BY source, version, package, bin_version
75     """
76
77     for row in session.execute(query_sources, {'archive_id': archive.archive_id}).fetchall():
78         (source, version, path) = row
79         print "Path: %s"%path
80         print "Source: %s"%source
81         print "Source-Version: %s"%version
82         print
83
84     for row in session.execute(query_binaries, {'archive_id': archive.archive_id}).fetchall():
85         (source, version, arch, path, bin, binv) = row
86         print "Path: %s"%path
87         print "Source: %s"%source
88         print "Source-Version: %s"%version
89         print "Architecture: %s"%arch
90         print "Binary: %s"%bin
91         print "Binary-Version: %s"%binv
92         print
93
94 ################################################################################
95
96 def usage():
97     print "usage: dak make-pkg-file-mapping <archive>"
98     sys.exit(0)
99
100 ################################################################################
101
102 def main():
103     if len(sys.argv) != 2:
104         usage()
105
106     archive_name = sys.argv[1]
107
108     session = DBConn().session()
109     archive = session.query(Archive).filter_by(archive_name=archive_name).one()
110     build_mapping(archive, session)
111
112 #########################################################################################
113
114 if __name__ == '__main__':
115     main()
116
117
118 # vim:set et:
119 # vim:set ts=4:
120 # vim:set shiftwidth=4: