]> git.decadent.org.uk Git - dak.git/blob - dak/contents.py
Add subcommand source-scan to 'dak contents'.
[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 from daklib import daklog
45 from daklib import utils
46
47 ################################################################################
48
49 def usage (exit_code=0):
50     print """Usage: dak contents [options] subcommand
51
52 SUBCOMMANDS
53     generate
54         generate Contents-$arch.gz files
55
56     binary-scan
57         scan the (u)debs in the existing pool and load contents into the
58         bin_contents table
59
60     source-scan
61         scan the source packages in the existing pool and load contents into
62         the src_contents table
63
64 OPTIONS
65      -h, --help
66         show this help and exit
67
68 OPTIONS for generate
69      -s, --suite={stable,testing,unstable,...}
70         only operate on specified suite names
71
72      -f, --force
73         write Contents files for suites marked as untouchable, too
74
75 OPTIONS for binary-scan and source-scan
76      -l, --limit=NUMBER
77         maximum number of packages to scan
78 """
79     sys.exit(exit_code)
80
81 ################################################################################
82
83 def write_all(cnf, suite_names = [], force = None):
84     Logger = daklog.Logger(cnf.Cnf, 'contents generate')
85     ContentsWriter.write_all(Logger, suite_names, force)
86     Logger.close()
87
88 ################################################################################
89
90 def binary_scan_all(cnf, limit):
91     Logger = daklog.Logger(cnf.Cnf, 'contents binary_scan')
92     result = BinaryContentsScanner.scan_all(limit)
93     processed = '%(processed)d packages processed' % result
94     remaining = '%(remaining)d packages remaining' % result
95     Logger.log([processed, remaining])
96     Logger.close()
97
98 ################################################################################
99
100 def source_scan_all(cnf, limit):
101     Logger = daklog.Logger(cnf.Cnf, 'contents source_scan')
102     result = SourceContentsScanner.scan_all(limit)
103     processed = '%(processed)d packages processed' % result
104     remaining = '%(remaining)d packages remaining' % result
105     Logger.log([processed, remaining])
106     Logger.close()
107
108 ################################################################################
109
110 def main():
111     cnf = Config()
112     cnf['Contents::Options::Help'] = ''
113     cnf['Contents::Options::Suite'] = ''
114     cnf['Contents::Options::Limit'] = ''
115     cnf['Contents::Options::Force'] = ''
116     arguments = [('h', "help",  'Contents::Options::Help'),
117                  ('s', "suite", 'Contents::Options::Suite', "HasArg"),
118                  ('l', "limit", 'Contents::Options::Limit', "HasArg"),
119                  ('f', "force", 'Contents::Options::Force'),
120                 ]
121     args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv)
122     options = cnf.SubTree('Contents::Options')
123
124     if (len(args) != 1) or options['Help']:
125         usage()
126
127     limit = None
128     if len(options['Limit']) > 0:
129         limit = int(options['Limit'])
130
131     if args[0] == 'binary_scan':
132         binary_scan_all(cnf, limit)
133         return
134
135     if args[0] == 'source_scan':
136         source_scan_all(cnf, limit)
137         return
138
139     suite_names = utils.split_args(options['Suite'])
140
141     force = bool(options['Force'])
142
143     if args[0] == 'generate':
144         write_all(cnf, suite_names, force)
145         return
146
147     usage()
148
149
150 if __name__ == '__main__':
151     main()