]> git.decadent.org.uk Git - dak.git/blob - dak/contents.py
Add a new subcommand 'generate_helper' 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 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(suite_names, force)
81     Logger.close()
82
83 ################################################################################
84
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_overridetype(argv[1], session)
90     if len(argv) == 3:
91         component = get_component(argv[2], session)
92     else:
93         component = None
94     session.rollback()
95     ContentsWriter(suite, architecture, debtype, component).write_file()
96     session.close()
97
98 ################################################################################
99
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])
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] == 'scan':
132         scan_all(cnf, limit)
133         return
134
135     suite_names = utils.split_args(options['Suite'])
136
137     force = bool(options['Force'])
138
139     if args[0] == 'generate':
140         write_all(cnf, suite_names, force)
141         return
142
143     if args[0] == 'generate_helper':
144         write_helper(suite_names[0], argv[1:])
145         return
146
147     usage()
148
149
150 if __name__ == '__main__':
151     main()