3 Create all the contents files
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
12 ################################################################################
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.
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.
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
28 ################################################################################
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.
34 # <Ganneff> of course that wont help for now where we need to generate them :)
36 ################################################################################
41 from daklib.config import Config
42 from daklib.dbconn import *
43 from daklib.contents import BinaryContentsScanner, ContentsWriter, \
45 from daklib import daklog
46 from daklib import utils
48 ################################################################################
50 def usage (exit_code=0):
51 print """Usage: dak contents [options] subcommand
55 generate Contents-$arch.gz files
58 scan the source packages in the existing pool and load contents into
59 the src_contents table
62 scan the (u)debs in the existing pool and load contents into the
67 show this help and exit
70 -s, --suite={stable,testing,unstable,...}
71 only operate on specified suite names
74 write Contents files for suites marked as untouchable, too
76 OPTIONS for scan-source and scan-binary
78 maximum number of packages to scan
82 ################################################################################
84 def write_all(cnf, suite_names = [], force = None):
85 Logger = daklog.Logger(cnf.Cnf, 'contents generate')
86 ContentsWriter.write_all(Logger, suite_names, force)
89 ################################################################################
91 def binary_scan_all(cnf, limit):
92 Logger = daklog.Logger(cnf.Cnf, 'contents scan-binary')
93 result = BinaryContentsScanner.scan_all(limit)
94 processed = '%(processed)d packages processed' % result
95 remaining = '%(remaining)d packages remaining' % result
96 Logger.log([processed, remaining])
99 ################################################################################
101 def source_scan_all(cnf, limit):
102 Logger = daklog.Logger(cnf.Cnf, 'contents scan-source')
103 result = SourceContentsScanner.scan_all(limit)
104 processed = '%(processed)d packages processed' % result
105 remaining = '%(remaining)d packages remaining' % result
106 Logger.log([processed, remaining])
109 ################################################################################
113 cnf['Contents::Options::Help'] = ''
114 cnf['Contents::Options::Suite'] = ''
115 cnf['Contents::Options::Limit'] = ''
116 cnf['Contents::Options::Force'] = ''
117 arguments = [('h', "help", 'Contents::Options::Help'),
118 ('s', "suite", 'Contents::Options::Suite', "HasArg"),
119 ('l', "limit", 'Contents::Options::Limit', "HasArg"),
120 ('f', "force", 'Contents::Options::Force'),
122 args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv)
123 options = cnf.SubTree('Contents::Options')
125 if (len(args) != 1) or options['Help']:
129 if len(options['Limit']) > 0:
130 limit = int(options['Limit'])
132 if args[0] == 'scan-source':
133 source_scan_all(cnf, limit)
136 if args[0] == 'scan-binary':
137 binary_scan_all(cnf, limit)
140 suite_names = utils.split_args(options['Suite'])
142 force = bool(options['Force'])
144 if args[0] == 'generate':
145 write_all(cnf, suite_names, force)
151 if __name__ == '__main__':