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 ContentsScanner, ContentsWriter
44 from daklib import daklog
45 from daklib import utils
47 ################################################################################
49 def usage (exit_code=0):
50 print """Usage: dak contents [options] subcommand
54 generate Contents-$arch.gz files
57 scan the debs in the existing pool and load contents into the bin_contents table
61 show this help and exit
64 -s, --suite={stable,testing,unstable,...}
65 only operate on specified suite names
68 write Contents files for suites marked as untouchable, too
72 maximum number of packages to scan
76 ################################################################################
78 def write_all(cnf, suite_names = [], force = None):
79 Logger = daklog.Logger(cnf.Cnf, 'contents generate')
80 ContentsWriter.write_all(suite_names, force)
83 ################################################################################
85 def write_helper(suite_name, argv):
86 session = DBConn().session()
87 suite = get_suite(suite_name, session)
88 architecture = get_architecture(argv[0], session)
89 debtype = get_override_type(argv[1], session)
91 component = get_component(argv[2], session)
95 ContentsWriter(suite, architecture, debtype, component).write_file()
98 ################################################################################
100 def scan_all(cnf, limit):
101 Logger = daklog.Logger(cnf.Cnf, 'contents scan')
102 result = ContentsScanner.scan_all(limit)
103 processed = '%(processed)d packages processed' % result
104 remaining = '%(remaining)d packages remaining' % result
105 Logger.log([processed, remaining])
108 ################################################################################
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'),
121 args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv)
122 options = cnf.SubTree('Contents::Options')
124 if (len(args) < 1) or options['Help']:
128 if len(options['Limit']) > 0:
129 limit = int(options['Limit'])
131 if args[0] == 'scan':
135 suite_names = utils.split_args(options['Suite'])
137 force = bool(options['Force'])
139 if args[0] == 'generate':
140 write_all(cnf, suite_names, force)
143 if args[0] == 'generate_helper':
144 write_helper(suite_names[0], args[1:])
150 if __name__ == '__main__':