From 6d8a488ead5007c85e56c0e1055e4faf05206515 Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Sun, 27 Mar 2011 09:42:40 +0000 Subject: [PATCH] Make external overrides specific for (suite, component) Signed-off-by: Ansgar Burchardt --- dak/dakdb/update60.py | 56 ++++++++++++++++++++++++ dak/external_overrides.py | 73 ++++++++++++++++++++++++------- dak/generate_packages_sources2.py | 4 +- dak/update_db.py | 2 +- daklib/dbconn.py | 7 ++- scripts/debian/byhand-tag | 5 ++- scripts/debian/byhand-task | 2 +- 7 files changed, 128 insertions(+), 21 deletions(-) create mode 100755 dak/dakdb/update60.py diff --git a/dak/dakdb/update60.py b/dak/dakdb/update60.py new file mode 100755 index 00000000..4cf6ee8f --- /dev/null +++ b/dak/dakdb/update60.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Make external overrides specific for (suite, component) + +@contact: Debian FTP Master +@copyright: 2011 Ansgar Burchardt +@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)) diff --git a/dak/external_overrides.py b/dak/external_overrides.py index a38fd5d2..9e212061 100755 --- a/dak/external_overrides.py +++ b/dak/external_overrides.py @@ -33,21 +33,16 @@ def usage(): 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'. @@ -56,14 +51,52 @@ 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 @@ -76,9 +109,10 @@ def external_overrides_import(key, file): 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: @@ -87,10 +121,17 @@ def main(): 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." diff --git a/dak/generate_packages_sources2.py b/dak/generate_packages_sources2.py index f055aa56..769b79da 100755 --- a/dak/generate_packages_sources2.py +++ b/dak/generate_packages_sources2.py @@ -165,7 +165,9 @@ SELECT || COALESCE(E'\n' || (SELECT STRING_AGG(key || '\: ' || value, E'\n' ORDER BY key) FROM external_overrides eo - WHERE eo.package = tmp.package + WHERE + eo.package = tmp.package + AND eo.suite = :overridesuite AND eo.component = :component ), '') || E'\nSection\: ' || sec.section || E'\nPriority\: ' || pri.priority diff --git a/dak/update_db.py b/dak/update_db.py index 447af0af..02ded358 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -46,7 +46,7 @@ from daklib.daklog import Logger ################################################################################ Cnf = None -required_database_schema = 59 +required_database_schema = 60 ################################################################################ diff --git a/daklib/dbconn.py b/daklib/dbconn.py index d39f8c58..55151527 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -3338,7 +3338,12 @@ class DBConn(object): poolfile_id = self.tbl_dsc_files.c.file, poolfile = relation(PoolFile))) - mapper(ExternalOverride, self.tbl_external_overrides) + mapper(ExternalOverride, self.tbl_external_overrides, + properties = dict( + suite_id = self.tbl_external_overrides.c.suite, + suite = relation(Suite), + component_id = self.tbl_external_overrides.c.component, + component = relation(Component))) mapper(PoolFile, self.tbl_files, properties = dict(file_id = self.tbl_files.c.id, diff --git a/scripts/debian/byhand-tag b/scripts/debian/byhand-tag index 9c24fb66..2bc6c87c 100755 --- a/scripts/debian/byhand-tag +++ b/scripts/debian/byhand-tag @@ -45,7 +45,10 @@ mv "$OUTNONFREE" "$TARGET"tag.non-free chmod 644 "$TARGET"tag "$TARGET"tag.contrib "$TARGET"tag.non-free (cd $TARGET && $scriptsdir/mk-extra-overrides.sh) -(cd "$TARGET" && cat tag tag.contrib tag.non-free | dak external-overrides import Tag) +(cd "$TARGET" \ + && dak external-overrides import unstable main Tag