--- /dev/null
+#!/usr/bin/env python
+# coding=utf8
+
+"""
+Make external overrides specific for (suite, component)
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2011 Ansgar Burchardt <ansgar@debian.org>
+@license: GNU General Public License version 2 or later
+"""
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+################################################################################
+
+import psycopg2
+from daklib.dak_exceptions import DBUpdateError
+
+################################################################################
+def do_update(self):
+ """
+ Make external overrides specific for (suite, component)
+ """
+ print __doc__
+ try:
+ c = self.db.cursor()
+
+ c.execute("DELETE FROM external_overrides")
+ print "NOTE: Please reimport the external overrides."
+
+ c.execute("""
+ ALTER TABLE external_overrides
+ DROP CONSTRAINT external_overrides_pkey,
+ ADD COLUMN suite INTEGER NOT NULL REFERENCES suite(id),
+ ADD COLUMN component INTEGER NOT NULL REFERENCES component(id),
+ ADD PRIMARY KEY (suite, component, package, key)
+ """)
+
+ c.execute("UPDATE config SET value = '60' WHERE name = 'db_revision'")
+ self.db.commit()
+
+ except psycopg2.ProgrammingError, msg:
+ self.db.rollback()
+ raise DBUpdateError, 'Unable to apply sick update 60, rollback issued. Error message : %s' % (str(msg))
print """Usage: dak external-overrides COMMAND
Modify external overrides.
- -h, --help show this help and exit.
+ -h, --help show this help and exit.
+ -f, --force allow processing of untouchable suites.
Commands can use a long or abbreviated form:
- remove KEY remove external overrides for KEY
- rm KEY
+ import SUITE COMPONENT KEY import external overrides for KEY
+ i SUITE COMPONENT KEY NOTE: This will replace existing overrides.
- import KEY import external overrides for KEY
- i KEY NOTE: This will replace existing overrides.
-
- show-key KEY show external overrides for KEY
- s-k KEY
-
- show-package PACKAGE show external overrides for PACKAGE
- s-p PACKAGE
+ copy FROM TO copy external overrides from suite FROM to TO
+ NOTE: Needs --force for untouchable TO
For the 'import' command, external overrides are read from standard input and
should be given as lines of the form 'PACKAGE KEY VALUE'.
#############################################################################
-def external_overrides_import(key, file):
+def external_overrides_copy(from_suite_name, to_suite_name, force = False):
+ session = DBConn().session()
+
+ from_suite = get_suite(from_suite_name, session)
+ to_suite = get_suite(to_suite_name, session)
+
+ if from_suite is None:
+ print "E: source %s not found." % from_suite_name
+ session.rollback()
+ return False
+ if to_suite is None:
+ print "E: target %s not found." % to_suite_name
+ session.rollback()
+ return False
+
+ if not force and to_suite.untouchable:
+ print "E: refusing to touch untouchable suite %s (not forced)." % to_suite_name
+ session.rollback()
+ return False
+
+ session.query(ExternalOverride).filter_by(suite=to_suite).delete()
+ session.execute("""
+ INSERT INTO external_overrides (suite, component, package, key, value)
+ SELECT :to_suite, component, package, key, value FROM external_overrides WHERE suite = :from_suite
+ """, { 'from_suite': from_suite.suite_id, 'to_suite': to_suite.suite_id })
+
+ session.commit()
+
+def external_overrides_import(suite_name, component_name, key, file, force = False):
session = DBConn().session()
- session.query(ExternalOverride).filter_by(key=key).delete()
+ suite = get_suite(suite_name, session)
+ component = get_component(component_name, session)
+
+ if not force and suite.untouchable:
+ print "E: refusing to touch untouchable suite %s (not forced)." % suite_name
+ session.rollback()
+ return False
+
+ session.query(ExternalOverride).filter_by(suite=suite,component=component,key=key).delete()
for line in file:
(package, key, value) = line.strip().split(None, 2)
eo = ExternalOverride()
+ eo.suite = suite
+ eo.component = component
eo.package = package
eo.key = key
eo.value = value
def main():
cnf = Config()
- Arguments = [('h',"help","External-Overrides::Options::Help")]
+ Arguments = [('h',"help","External-Overrides::Options::Help"),
+ ('f','force','External-Overrides::Options::Force')]
- (command, arg) = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
+ args = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
try:
Options = cnf.SubTree("External-Overrides::Options")
except KeyError:
if Options.has_key("Help"):
usage()
+ force = False
+ if Options.has_key("Force") and Options["Force"]:
+ force = True
+
logger = daklog.Logger(cnf, 'external-overrides')
+ command = args[0]
if command in ('import', 'i'):
- external_overrides_import(arg, sys.stdin)
+ external_overrides_import(args[1], args[2], args[3], sys.stdin, force)
+ elif command in ('copy', 'c'):
+ external_overrides_copy(args[1], args[2], force)
else:
print "E: Unknown commands."