]> git.decadent.org.uk Git - dak.git/blob - dak/external_overrides.py
Merge remote-tracking branch 'ansgar/p-s-from-db' into merge
[dak.git] / dak / external_overrides.py
1 #!/usr/bin/python
2
3 """
4 Modify external overrides.
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2011  Ansgar Burchardt <ansgar@debian.org>
8 @license: GNU General Public License version 2 or later
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 from daklib.dbconn import *
26 from daklib.config import Config
27 from daklib import utils, daklog
28
29 import apt_pkg
30 import sys
31
32 def usage():
33     print """Usage: dak external-overrides COMMAND
34 Modify external overrides.
35
36   -h, --help show this help and exit.
37
38 Commands can use a long or abbreviated form:
39
40     remove KEY                 remove external overrides for KEY
41     rm KEY
42
43     import KEY                 import external overrides for KEY
44     i KEY                      NOTE: This will replace existing overrides.
45
46     show-key KEY               show external overrides for KEY
47     s-k KEY
48
49     show-package PACKAGE       show external overrides for PACKAGE
50     s-p PACKAGE
51
52 For the 'import' command, external overrides are read from standard input and
53 should be given as lines of the form 'PACKAGE KEY VALUE'.
54 """
55     sys.exit()
56
57 #############################################################################
58
59 def external_overrides_import(key, file):
60     session = DBConn().session()
61
62     session.query(ExternalOverride).filter_by(key=key).delete()
63
64     for line in file:
65         (package, key, value) = line.strip().split(None, 2)
66         eo = ExternalOverride()
67         eo.package = package
68         eo.key = key
69         eo.value = value
70         session.add(eo)
71
72     session.commit()
73
74 #############################################################################
75
76 def main():
77     cnf = Config()
78
79     Arguments = [('h',"help","External-Overrides::Options::Help")]
80
81     (command, arg) = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
82     try:
83         Options = cnf.SubTree("External-Overrides::Options")
84     except KeyError:
85         Options = {}
86
87     if Options.has_key("Help"):
88         usage()
89
90     logger = daklog.Logger(cnf, 'external-overrides')
91
92     if command in ('import', 'i'):
93         external_overrides_import(arg, sys.stdin)
94     else:
95         print "E: Unknown commands."
96
97 if __name__ == '__main__':
98     main()