4 Modify external overrides.
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
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.
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.
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
25 from daklib.dbconn import *
26 from daklib.config import Config
27 from daklib import utils, daklog
33 print """Usage: dak external-overrides COMMAND
34 Modify external overrides.
36 -h, --help show this help and exit.
37 -f, --force allow processing of untouchable suites.
39 Commands can use a long or abbreviated form:
41 import SUITE COMPONENT KEY import external overrides for KEY
42 i SUITE COMPONENT KEY NOTE: This will replace existing overrides.
44 copy FROM TO copy external overrides from suite FROM to TO
45 NOTE: Needs --force for untouchable TO
47 For the 'import' command, external overrides are read from standard input and
48 should be given as lines of the form 'PACKAGE KEY VALUE'.
52 #############################################################################
54 class ExternalOverrideReader(object):
56 Parses an external override file
58 def __init__(self, fh):
66 Return the parsed line that is being built and start parsing a new line
68 res = self.package, self.key, "\n".join(self.value)
69 self.package = self.key = None
75 returns a (package, key, value) tuple for every entry in the external
80 if line[0] in (" ", "\t"):
82 self.value.append(line.rstrip())
84 if self.package is not None:
88 (self.package, self.key, value) = line.rstrip().split(None, 2)
91 if self.package is not None:
94 #############################################################################
96 def external_overrides_copy(from_suite_name, to_suite_name, force = False):
97 session = DBConn().session()
99 from_suite = get_suite(from_suite_name, session)
100 to_suite = get_suite(to_suite_name, session)
102 if from_suite is None:
103 print "E: source %s not found." % from_suite_name
107 print "E: target %s not found." % to_suite_name
111 if not force and to_suite.untouchable:
112 print "E: refusing to touch untouchable suite %s (not forced)." % to_suite_name
116 session.query(ExternalOverride).filter_by(suite=to_suite).delete()
118 INSERT INTO external_overrides (suite, component, package, key, value)
119 SELECT :to_suite, component, package, key, value FROM external_overrides WHERE suite = :from_suite
120 """, { 'from_suite': from_suite.suite_id, 'to_suite': to_suite.suite_id })
124 def external_overrides_import(suite_name, component_name, key, file, force = False):
125 session = DBConn().session()
127 suite = get_suite(suite_name, session)
128 component = get_component(component_name, session)
130 if not force and suite.untouchable:
131 print "E: refusing to touch untouchable suite %s (not forced)." % suite_name
135 session.query(ExternalOverride).filter_by(suite=suite,component=component,key=key).delete()
137 for package, key, value in ExternalOverrideReader(file):
138 eo = ExternalOverride()
140 eo.component = component
148 #############################################################################
153 Arguments = [('h',"help","External-Overrides::Options::Help"),
154 ('f','force','External-Overrides::Options::Force')]
156 args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
158 Options = cnf.subtree("External-Overrides::Options")
162 if Options.has_key("Help"):
166 if Options.has_key("Force") and Options["Force"]:
169 logger = daklog.Logger('external-overrides')
172 if command in ('import', 'i'):
173 external_overrides_import(args[1], args[2], args[3], sys.stdin, force)
174 elif command in ('copy', 'c'):
175 external_overrides_copy(args[1], args[2], force)
177 print "E: Unknown commands."
179 if __name__ == '__main__':