]> git.decadent.org.uk Git - dak.git/blob - dak/contents.py
Merge branch '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 ContentsScanner, 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     scan
57         scan the debs in the existing pool and load contents into the bin_contents table
58
59 OPTIONS
60      -h, --help
61         show this help and exit
62
63 OPTIONS for generate
64      -s, --suite={stable,testing,unstable,...}
65         only operate on specified suite names
66
67      -f, --force
68         write Contents files for suites marked as untouchable, too
69
70 OPTIONS for scan
71      -l, --limit=NUMBER
72         maximum number of packages to scan
73 """
74     sys.exit(exit_code)
75
76 ################################################################################
77
78 def write_all(cnf, suite_names = [], force = None):
79     Logger = daklog.Logger(cnf.Cnf, 'contents generate')
80     ContentsWriter.write_all(Logger, suite_names, force)
81     Logger.close()
82
83 ################################################################################
84
85 def scan_all(cnf, limit):
86     Logger = daklog.Logger(cnf.Cnf, 'contents scan')
87     result = ContentsScanner.scan_all(limit)
88     processed = '%(processed)d packages processed' % result
89     remaining = '%(remaining)d packages remaining' % result
90     Logger.log([processed, remaining])
91     Logger.close()
92
93 ################################################################################
94
95 def main():
96     cnf = Config()
97     cnf['Contents::Options::Help'] = ''
98     cnf['Contents::Options::Suite'] = ''
99     cnf['Contents::Options::Limit'] = ''
100     cnf['Contents::Options::Force'] = ''
101     arguments = [('h', "help",  'Contents::Options::Help'),
102                  ('s', "suite", 'Contents::Options::Suite', "HasArg"),
103                  ('l', "limit", 'Contents::Options::Limit', "HasArg"),
104                  ('f', "force", 'Contents::Options::Force'),
105                 ]
106     args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv)
107     options = cnf.SubTree('Contents::Options')
108
109     if (len(args) != 1) or options['Help']:
110         usage()
111
112     limit = None
113     if len(options['Limit']) > 0:
114         limit = int(options['Limit'])
115
116     if args[0] == 'scan':
117         scan_all(cnf, limit)
118         return
119
120     suite_names = utils.split_args(options['Suite'])
121
122     force = bool(options['Force'])
123
124     if args[0] == 'generate':
125         write_all(cnf, suite_names, force)
126         return
127
128     usage()
129
130
131 if __name__ == '__main__':
132     main()