]> git.decadent.org.uk Git - dak.git/blob - dak/make_pkg_file_mapping.py
Add make_pkg_file_mapping.py
[dak.git] / dak / make_pkg_file_mapping.py
1 #!/usr/bin/env python
2
3 import os
4 import pg
5 import sys
6 from daklib import database
7 from daklib import utils
8
9 ################################################################################
10
11 projectB = None #: database connection, pgobject
12
13 ################################################################################
14
15 # Usage: dak make-pkg_file_mapping
16 #
17 # Prints out, for every file in the pool, which source package and version it
18 # belongs to and for binary packages additionally which arch, binary package
19 # and binary package version it has in a standard rfc2822-like format.
20
21 # Copyright 2009 Peter Palfrader <peter@palfrader.org>
22 #
23 # This program is free software; you can redistribute it and/or modify
24 # it under the terms of the GNU General Public License as published by
25 # the Free Software Foundation; either version 2 of the License, or
26 # (at your option) any later version.
27 #
28 # This program is distributed in the hope that it will be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 # GNU General Public License for more details.
32 #
33 # You should have received a copy of the GNU General Public License
34 # along with this program; if not, write to the Free Software
35 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
36
37 ################################################################################
38
39 def build_mapping():
40     # The ORDER BY is in the queries so that compression of the output works
41     # better.  It's the difference between a 9 megabyte bzip2 and a 2.5 mb
42     # bzip2 file.
43
44     query_sources = """
45     SELECT
46         source.source,
47         source.version,
48         './pool/' || files.filename AS path
49     FROM source
50       JOIN dsc_files ON source.id=dsc_files.source
51       JOIN files ON files.id=dsc_files.file
52     ORDER BY source, version
53     """
54
55     query_binaries = """
56     SELECT
57         source.source,
58         source.version,
59         architecture.arch_string AS arch,
60         './pool/' || files.filename AS path,
61         binaries.package,
62         binaries.version AS bin_version
63     FROM source
64       JOIN binaries ON source.id=binaries.source
65       JOIN files ON binaries.file=files.id
66       JOIN architecture ON architecture.id=binaries.architecture
67     ORDER BY source, version, package, bin_version
68     """
69
70     for i in projectB.query(query_sources).getresult():
71         (source, version, path) = i
72         print "Path: %s"%path
73         print "Source: %s"%source
74         print "Source-Version: %s"%version
75         print
76
77     for i in projectB.query(query_binaries).getresult():
78         (source, version, arch, path, bin, binv) = i
79         print "Path: %s"%path
80         print "Source: %s"%source
81         print "Source-Version: %s"%version
82         print "Architecture: %s"%arch
83         print "Binary: %s"%bin
84         print "Binary-Version: %s"%binv
85         print
86
87 ################################################################################
88
89 def main():
90     global projectB
91
92     Cnf = utils.get_conf()
93     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
94     build_mapping()
95
96 #########################################################################################
97
98 if __name__ == '__main__':
99     main()
100
101
102 # vim:set et:
103 # vim:set ts=4:
104 # vim:set shiftwidth=4: