X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fdakdb%2Fupdate28.py;h=f0c62e0e8176ba26c027943f6adde5b36bcf9739;hb=9a4fb568340b14698947bfa59b309ae0c67c693a;hp=6e73c7508118937ab34dad25166a5c045b4506e7;hpb=f312f4c7b63d193fa80ca45ff6bfb6114750fd63;p=dak.git diff --git a/dak/dakdb/update28.py b/dak/dakdb/update28.py old mode 100644 new mode 100755 index 6e73c750..f0c62e0e --- a/dak/dakdb/update28.py +++ b/dak/dakdb/update28.py @@ -31,19 +31,16 @@ keep contents of binary packages in tables so we can generate contents.gz files import psycopg2 import time from daklib.dak_exceptions import DBUpdateError +from daklib.config import Config +import string ################################################################################ -def suites(): +def _suites(): """ return a list of suites to operate on """ - if Config().has_key( "%s::%s" %(options_prefix,"Suite")): - suites = utils.split_args(Config()[ "%s::%s" %(options_prefix,"Suite")]) - else: - suites = [ 'unstable', 'testing' ] -# suites = Config().SubTree("Suite").List() - + suites = Config().subtree("Suite").list() return suites def arches(cursor, suite): @@ -54,7 +51,7 @@ def arches(cursor, suite): cursor.execute("""SELECT s.architecture, a.arch_string FROM suite_architectures s JOIN architecture a ON (s.architecture=a.id) - WHERE suite = :suite""", {'suite' : suite }) + WHERE suite = '%s'""" % suite) while True: r = cursor.fetchone() @@ -142,20 +139,24 @@ def do_update(self): c.execute("""CREATE INDEX ind_deb_contents_binary ON deb_contents(binary_id);""" ) - - suites = self.suites() + suites = _suites() for suite in [i.lower() for i in suites]: - suite_id = DBConn().get_suite_id(suite) + + c.execute("SELECT id FROM suite WHERE suite_name ='%s'" % suite ) + suiterow = c.fetchone() + suite_id = suiterow[0] arch_list = arches(c, suite_id) arch_list = arches(c, suite_id) + suitestr=string.replace(suite,'-','_'); for (arch_id,arch_str) in arch_list: - c.execute( "CREATE INDEX ind_deb_contents_%s_%s ON deb_contents (arch,suite) WHERE (arch=2 OR arch=%d) AND suite=$d"%(arch_str,suite,arch_id,suite_id) ) + arch_str = string.replace(arch_str,"-", "_") + c.execute( "CREATE INDEX ind_deb_contents_%s_%s ON deb_contents (arch,suite) WHERE (arch=2 OR arch=%s) AND suite='%s'"%(arch_str,suitestr,arch_id,suite_id) ) for section, sname in [("debian-installer","main"), ("non-free/debian-installer", "nonfree")]: - c.execute( "CREATE INDEX ind_udeb_contents_%s_%s ON udeb_contents (section,suite) WHERE section=%s AND suite=$d"%(sname,suite,section,suite_id) ) + c.execute( "CREATE INDEX ind_udeb_contents_%s_%s ON udeb_contents (section,suite) WHERE section='%s' AND suite='%s'"%(sname,suitestr,section,suite_id) ) c.execute( """CREATE OR REPLACE FUNCTION update_contents_for_bin_a() RETURNS trigger AS $$ @@ -169,7 +170,7 @@ def do_update(self): if event == "INSERT" or event == "UPDATE": content_data = plpy.execute(plpy.prepare( - """SELECT s.section, b.package, b.architecture, ot.type + \"\"\"SELECT s.section, b.package, b.architecture, ot.type FROM override o JOIN override_type ot on o.type=ot.id JOIN binaries b on b.package=o.package @@ -178,14 +179,14 @@ def do_update(self): JOIN section s on s.id=o.section WHERE b.id=$1 AND o.suite=$2 - """, + \"\"\", ["int", "int"]), [TD["new"]["bin"], TD["new"]["suite"]])[0] tablename="%s_contents" % content_data['type'] - plpy.execute(plpy.prepare("""DELETE FROM %s - WHERE package=$1 and arch=$2 and suite=$3""" % tablename, + plpy.execute(plpy.prepare(\"\"\"DELETE FROM %s + WHERE package=$1 and arch=$2 and suite=$3\"\"\" % tablename, ['text','int','int']), [content_data['package'], content_data['architecture'], @@ -198,9 +199,9 @@ def do_update(self): for filename in filenames: plpy.execute(plpy.prepare( - """INSERT INTO %s + \"\"\"INSERT INTO %s (filename,section,package,binary_id,arch,suite) - VALUES($1,$2,$3,$4,$5,$6)""" % tablename, + VALUES($1,$2,$3,$4,$5,$6)\"\"\" % tablename, ["text","text","text","int","int","int"]), [filename["file"], content_data["section"], @@ -235,9 +236,9 @@ $$ LANGUAGE plpythonu VOLATILE SECURITY DEFINER; event = TD["event"] if event == "UPDATE" or event == "INSERT": row = TD["new"] - r = plpy.execute(plpy.prepare( """SELECT 1 from suite_architectures sa + r = plpy.execute(plpy.prepare( \"\"\"SELECT 1 from suite_architectures sa JOIN binaries b ON b.architecture = sa.architecture - WHERE b.id = $1 and sa.suite = $2""", + WHERE b.id = $1 and sa.suite = $2\"\"\", ["int", "int"]), [row["bin"], row["suite"]]) if not len(r): @@ -264,7 +265,7 @@ $$ LANGUAGE plpythonu VOLATILE;""") self.db.commit() - except psycopg2.ProgrammingError, msg: + except psycopg2.ProgrammingError as msg: self.db.rollback() - raise DBUpdateError, "Unable to apply process-new update 28, rollback issued. Error message : %s" % (str(msg)) + raise DBUpdateError("Unable to apply process-new update 28, rollback issued. Error message : %s" % (str(msg)))