]> git.decadent.org.uk Git - dak.git/blob - dak/contents.py
Adjust to deal with the new Debian supplementaryGid
[dak.git] / dak / contents.py
1 #!/usr/bin/env python
2 """
3 Create all the contents files
4
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2008, 2009 Michael Casadevall <mcasadevall@debian.org>
7 @copyright: 2009 Mike O'Connor <stew@debian.org>
8 @copyright: 2011 Torsten Werner <twerner@debian.org>
9 @license: GNU General Public License version 2 or later
10 """
11
12 ################################################################################
13
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
28 ################################################################################
29
30 # <Ganneff> there is the idea to slowly replace contents files
31 # <Ganneff> with a new generation of such files.
32 # <Ganneff> having more info.
33
34 # <Ganneff> of course that wont help for now where we need to generate them :)
35
36 ################################################################################
37
38 import sys
39 import apt_pkg
40
41 from daklib.config import Config
42 from daklib.dbconn import *
43 from daklib.contents import BinaryContentsScanner, ContentsWriter, \
44     SourceContentsScanner
45 from daklib import daklog
46 from daklib import utils
47
48 ################################################################################
49
50 def usage (exit_code=0):
51     print """Usage: dak contents [options] subcommand
52
53 SUBCOMMANDS
54     generate
55         generate Contents-$arch.gz files
56
57     scan-source
58         scan the source packages in the existing pool and load contents into
59         the src_contents table
60
61     scan-binary
62         scan the (u)debs in the existing pool and load contents into the
63         bin_contents table
64
65 OPTIONS
66      -h, --help
67         show this help and exit
68
69 OPTIONS for generate
70      -a, --archive=ARCHIVE
71         only operate on suites in the specified archive
72
73      -s, --suite={stable,testing,unstable,...}
74         only operate on specified suite names
75
76      -c, --component={main,contrib,non-free}
77         only operate on specified components
78
79      -f, --force
80         write Contents files for suites marked as untouchable, too
81
82 OPTIONS for scan-source and scan-binary
83      -l, --limit=NUMBER
84         maximum number of packages to scan
85 """
86     sys.exit(exit_code)
87
88 ################################################################################
89
90 def write_all(cnf, archive_names = [], suite_names = [], component_names = [], force = None):
91     Logger = daklog.Logger('contents generate')
92     ContentsWriter.write_all(Logger, archive_names, suite_names, component_names, force)
93     Logger.close()
94
95 ################################################################################
96
97 def binary_scan_all(cnf, limit):
98     Logger = daklog.Logger('contents scan-binary')
99     result = BinaryContentsScanner.scan_all(limit)
100     processed = '%(processed)d packages processed' % result
101     remaining = '%(remaining)d packages remaining' % result
102     Logger.log([processed, remaining])
103     Logger.close()
104
105 ################################################################################
106
107 def source_scan_all(cnf, limit):
108     Logger = daklog.Logger('contents scan-source')
109     result = SourceContentsScanner.scan_all(limit)
110     processed = '%(processed)d packages processed' % result
111     remaining = '%(remaining)d packages remaining' % result
112     Logger.log([processed, remaining])
113     Logger.close()
114
115 ################################################################################
116
117 def main():
118     cnf = Config()
119     cnf['Contents::Options::Help'] = ''
120     cnf['Contents::Options::Suite'] = ''
121     cnf['Contents::Options::Component'] = ''
122     cnf['Contents::Options::Limit'] = ''
123     cnf['Contents::Options::Force'] = ''
124     arguments = [('h', "help",      'Contents::Options::Help'),
125                  ('a', 'archive',   'Contents::Options::Archive',   'HasArg'),
126                  ('s', "suite",     'Contents::Options::Suite',     "HasArg"),
127                  ('c', "component", 'Contents::Options::Component', "HasArg"),
128                  ('l', "limit",     'Contents::Options::Limit',     "HasArg"),
129                  ('f', "force",     'Contents::Options::Force'),
130                 ]
131     args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)
132     options = cnf.subtree('Contents::Options')
133
134     if (len(args) != 1) or options['Help']:
135         usage()
136
137     limit = None
138     if len(options['Limit']) > 0:
139         limit = int(options['Limit'])
140
141     if args[0] == 'scan-source':
142         source_scan_all(cnf, limit)
143         return
144
145     if args[0] == 'scan-binary':
146         binary_scan_all(cnf, limit)
147         return
148
149     archive_names   = utils.split_args(options['Archive'])
150     suite_names     = utils.split_args(options['Suite'])
151     component_names = utils.split_args(options['Component'])
152
153     force = bool(options['Force'])
154
155     if args[0] == 'generate':
156         write_all(cnf, archive_names, suite_names, component_names, force)
157         return
158
159     usage()
160
161
162 if __name__ == '__main__':
163     main()