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