]> git.decadent.org.uk Git - dak.git/blob - dak/packagescan.py
Start work on Packages import
[dak.git] / dak / packagescan.py
1 #!/usr/bin/env python
2 """
3 Import data for Packages files from .deb 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 @copyright: 2011 Mark Hymers <mhy@debian.org>
10 @license: GNU General Public License version 2 or later
11 """
12
13 ################################################################################
14
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
29 ################################################################################
30
31 # < mvo> that screams for consolidation in libapt at least (that then in turn can
32 #        use libdpkg ... ) - I guess the "d" means delayed ;)
33
34 # (whilst discussing adding xz support to dak, and therefore python-apt, and
35 #        therefore libapt-pkg)
36
37 ################################################################################
38
39 import sys
40 import apt_pkg
41
42 from daklib.config import Config
43 from daklib.dbconn import *
44 from daklib.packages import PackagesScanner
45 from daklib import daklog
46 from daklib import utils
47
48 ################################################################################
49
50 def usage (exit_code=0):
51     print """Usage: dak packagescan [options] subcommand
52
53 SUBCOMMANDS
54     scan
55         scan the debs in the existing pool and load metadata into the database
56
57 OPTIONS
58      -h, --help
59         show this help and exit
60
61 OPTIONS for scan
62      -l, --limit=NUMBER
63         maximum number of packages to scan
64 """
65     sys.exit(exit_code)
66
67 ################################################################################
68
69 def scan_all(cnf, limit):
70     Logger = daklog.Logger(cnf.Cnf, 'packages scan')
71     result = PackagesScanner.scan_all(limit)
72     processed = '%(processed)d packages processed' % result
73     remaining = '%(remaining)d packages remaining' % result
74     Logger.log([processed, remaining])
75     Logger.close()
76
77 ################################################################################
78
79 def main():
80     cnf = Config()
81     cnf['Packages::Options::Help'] = ''
82     cnf['Packages::Options::Suite'] = ''
83     cnf['Packages::Options::Limit'] = ''
84     cnf['Packages::Options::Force'] = ''
85     arguments = [('h', "help",  'Packages::Options::Help'),
86                  ('s', "suite", 'Packages::Options::Suite', "HasArg"),
87                  ('l', "limit", 'Packages::Options::Limit', "HasArg"),
88                  ('f', "force", 'Packages::Options::Force'),
89                 ]
90     args = apt_pkg.ParseCommandLine(cnf.Cnf, arguments, sys.argv)
91     options = cnf.SubTree('Packages::Options')
92
93     if (len(args) != 1) or options['Help']:
94         usage()
95
96     limit = None
97     if len(options['Limit']) > 0:
98         limit = int(options['Limit'])
99
100     if args[0] == 'scan':
101         scan_all(cnf, limit)
102         return
103
104     suite_names = utils.split_args(options['Suite'])
105
106     force = bool(options['Force'])
107
108     if args[0] == 'generate':
109         raise NotImplementError
110
111     usage()
112
113
114 if __name__ == '__main__':
115     main()