]> git.decadent.org.uk Git - dak.git/blob - dak/make_pkg_file_mapping.py
make_pkg_file_mapping
[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 os
35 import pg
36 import sys
37 from daklib import database
38 from daklib import utils
39
40 ################################################################################
41
42 projectB = None #: database connection, pgobject
43
44 ################################################################################
45
46 def build_mapping():
47     # The ORDER BY is in the queries so that compression of the output works
48     # better.  It's the difference between a 9 megabyte bzip2 and a 2.5 mb
49     # bzip2 file.
50
51     query_sources = """
52     SELECT
53         source.source,
54         source.version,
55         './pool/' || files.filename AS path
56     FROM source
57       JOIN dsc_files ON source.id=dsc_files.source
58       JOIN files ON files.id=dsc_files.file
59     ORDER BY source, version
60     """
61
62     query_binaries = """
63     SELECT
64         source.source,
65         source.version,
66         architecture.arch_string AS arch,
67         './pool/' || files.filename AS path,
68         binaries.package,
69         binaries.version AS bin_version
70     FROM source
71       JOIN binaries ON source.id=binaries.source
72       JOIN files ON binaries.file=files.id
73       JOIN architecture ON architecture.id=binaries.architecture
74     ORDER BY source, version, package, bin_version
75     """
76
77     for row in projectB.query(query_sources).getresult():
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 projectB.query(query_binaries).getresult():
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 main():
97     global projectB
98
99     Cnf = utils.get_conf()
100     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
101     build_mapping()
102
103 #########################################################################################
104
105 if __name__ == '__main__':
106     main()
107
108
109 # vim:set et:
110 # vim:set ts=4:
111 # vim:set shiftwidth=4: