From 990fa476b62675b41eb77dcfa3041d875e2630b4 Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Sat, 26 Mar 2011 18:08:37 +0000 Subject: [PATCH] Add external-overrides. Signed-off-by: Ansgar Burchardt --- dak/dak.py | 2 + dak/dakdb/update59.py | 56 ++++++++++++++++++++++ dak/external_overrides.py | 98 +++++++++++++++++++++++++++++++++++++++ dak/update_db.py | 2 +- daklib/dbconn.py | 14 ++++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100755 dak/dakdb/update59.py create mode 100755 dak/external_overrides.py diff --git a/dak/dak.py b/dak/dak.py index 304af5f1..b8b9f62d 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -153,6 +153,8 @@ def init(): "Copies the installer from one suite to another"), ("override-disparity", "Generate a list of override disparities"), + ("external-overrides", + "Modify external overrides"), ] return functionality diff --git a/dak/dakdb/update59.py b/dak/dakdb/update59.py new file mode 100755 index 00000000..6417a370 --- /dev/null +++ b/dak/dakdb/update59.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Add external_overrides + +@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): + """ + Add external_overrides + """ + print __doc__ + try: + c = self.db.cursor() + + c.execute(""" + CREATE TABLE external_overrides ( + package TEXT NOT NULL, + key TEXT NOT NULL, + value TEXT NOT NULL, + PRIMARY KEY (package, key) + )"""); + + c.execute("GRANT SELECT, UPDATE, INSERT, DELETE ON external_overrides TO ftpmaster"); + c.execute("GRANT SELECT ON external_overrides TO public"); + + c.execute("UPDATE config SET value = '59' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError, msg: + self.db.rollback() + raise DBUpdateError, 'Unable to apply sick update 59, rollback issued. Error message : %s' % (str(msg)) diff --git a/dak/external_overrides.py b/dak/external_overrides.py new file mode 100755 index 00000000..a38fd5d2 --- /dev/null +++ b/dak/external_overrides.py @@ -0,0 +1,98 @@ +#!/usr/bin/python + +""" +Modify external overrides. + +@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 + +from daklib.dbconn import * +from daklib.config import Config +from daklib import utils, daklog + +import apt_pkg +import sys + +def usage(): + print """Usage: dak external-overrides COMMAND +Modify external overrides. + + -h, --help show this help and exit. + +Commands can use a long or abbreviated form: + + remove KEY remove external overrides for KEY + rm KEY + + 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 + +For the 'import' command, external overrides are read from standard input and +should be given as lines of the form 'PACKAGE KEY VALUE'. +""" + sys.exit() + +############################################################################# + +def external_overrides_import(key, file): + session = DBConn().session() + + session.query(ExternalOverride).filter_by(key=key).delete() + + for line in file: + (package, key, value) = line.strip().split(None, 2) + eo = ExternalOverride() + eo.package = package + eo.key = key + eo.value = value + session.add(eo) + + session.commit() + +############################################################################# + +def main(): + cnf = Config() + + Arguments = [('h',"help","External-Overrides::Options::Help")] + + (command, arg) = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv) + try: + Options = cnf.SubTree("External-Overrides::Options") + except KeyError: + Options = {} + + if Options.has_key("Help"): + usage() + + logger = daklog.Logger(cnf, 'external-overrides') + + if command in ('import', 'i'): + external_overrides_import(arg, sys.stdin) + else: + print "E: Unknown commands." + +if __name__ == '__main__': + main() diff --git a/dak/update_db.py b/dak/update_db.py index 75d45dff..447af0af 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 = 58 +required_database_schema = 59 ################################################################################ diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 8da26063..c6612b72 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -1352,6 +1352,17 @@ __all__.append('get_dscfiles') ################################################################################ +class ExternalOverride(ORMObject): + def __init__(self, *args, **kwargs): + pass + + def __repr__(self): + return '' % (self.package, self.key, self.value) + +__all__.append('ExternalOverride') + +################################################################################ + class PoolFile(ORMObject): def __init__(self, filename = None, location = None, filesize = -1, \ md5sum = None): @@ -3184,6 +3195,7 @@ class DBConn(object): 'changes_pending_source_files', 'changes_pool_files', 'dsc_files', + 'external_overrides', 'extra_src_references', 'files', 'fingerprint', @@ -3318,6 +3330,8 @@ class DBConn(object): poolfile_id = self.tbl_dsc_files.c.file, poolfile = relation(PoolFile))) + mapper(ExternalOverride, self.tbl_external_overrides) + mapper(PoolFile, self.tbl_files, properties = dict(file_id = self.tbl_files.c.id, filesize = self.tbl_files.c.size, -- 2.39.2