-class InitDB(object):
- def __init__(self, Cnf, projectB):
- self.Cnf = Cnf
- self.projectB = projectB
-
- def do_archive(self):
- """Initalize the archive table."""
-
- c = self.projectB.cursor()
- c.execute("DELETE FROM archive")
- archive_add = "INSERT INTO archive (name, origin_server, description) VALUES (%s, %s, %s)"
- for name in self.Cnf.SubTree("Archive").List():
- archive_config = self.Cnf.SubTree("Archive::%s" % (name))
- origin_server = sql_get(archive_config, "OriginServer")
- description = sql_get(archive_config, "Description")
- c.execute(archive_add, [name, origin_server, description])
- self.projectB.commit()
-
- def do_architecture(self):
- """Initalize the architecture table."""
-
- c = self.projectB.cursor()
- c.execute("DELETE FROM architecture")
- arch_add = "INSERT INTO architecture (arch_string, description) VALUES (%s, %s)"
- for arch in self.Cnf.SubTree("Architectures").List():
- description = self.Cnf["Architectures::%s" % (arch)]
- c.execute(arch_add, [arch, description])
- self.projectB.commit()
-
- def do_component(self):
- """Initalize the component table."""
-
- c = self.projectB.cursor()
- c.execute("DELETE FROM component")
-
- comp_add = "INSERT INTO component (name, description, meets_dfsg) " + \
- "VALUES (%s, %s, %s)"
-
- for name in self.Cnf.SubTree("Component").List():
- component_config = self.Cnf.SubTree("Component::%s" % (name))
- description = sql_get(component_config, "Description")
- meets_dfsg = (component_config.get("MeetsDFSG").lower() == "true")
- c.execute(comp_add, [name, description, meets_dfsg])
-
- self.projectB.commit()
-
- def do_location(self):
- """Initalize the location table."""
-
- c = self.projectB.cursor()
- c.execute("DELETE FROM location")
-
- loc_add_mixed = "INSERT INTO location (path, archive, type) " + \
- "VALUES (%s, %s, %s)"
-
- loc_add = "INSERT INTO location (path, component, archive, type) " + \
- "VALUES (%s, %s, %s, %s)"
-
- for location in self.Cnf.SubTree("Location").List():
- location_config = self.Cnf.SubTree("Location::%s" % (location))
- archive_id = self.projectB.get_archive_id(location_config["Archive"])
- if archive_id == -1:
- utils.fubar("Archive '%s' for location '%s' not found."
- % (location_config["Archive"], location))
- location_type = location_config.get("type")
- if location_type == "legacy-mixed":
- c.execute(loc_add_mixed, [location, archive_id, location_config["type"]])
- elif location_type == "legacy" or location_type == "pool":
- for component in self.Cnf.SubTree("Component").List():
- component_id = self.projectB.get_component_id(component)
- c.execute(loc_add, [location, component_id, archive_id, location_type])
- else:
- utils.fubar("E: type '%s' not recognised in location %s."
- % (location_type, location))
-
- self.projectB.commit()
-
- def do_suite(self):
- """Initalize the suite table."""
-
- c = self.projectB.cursor()
- c.execute("DELETE FROM suite")
-
- suite_add = "INSERT INTO suite (suite_name, version, origin, description) " + \
- "VALUES (%s, %s, %s, %s)"
-
- sa_add = "INSERT INTO suite_architectures (suite, architecture) " + \
- "VALUES (currval('suite_id_seq'), %s)"
-
- for suite in self.Cnf.SubTree("Suite").List():
- suite_config = self.Cnf.SubTree("Suite::%s" %(suite))
- version = sql_get(suite_config, "Version")
- origin = sql_get(suite_config, "Origin")
- description = sql_get(suite_config, "Description")
- c.execute(suite_add, [suite.lower(), version, origin, description])
- for architecture in self.Cnf.ValueList("Suite::%s::Architectures" % (suite)):
- architecture_id = self.projectB.get_architecture_id (architecture)
- if architecture_id < 0:
- utils.fubar("architecture '%s' not found in architecture"
- " table for suite %s."
+def do_archive():
+ """Initalize the archive table."""
+
+ projectB.query("BEGIN WORK")
+ projectB.query("DELETE FROM archive")
+ for name in Cnf.SubTree("Archive").List():
+ archive_config = Cnf.SubTree("Archive::%s" % (name))
+ origin_server = sql_get(archive_config, "OriginServer")
+ description = sql_get(archive_config, "Description")
+ projectB.query("INSERT INTO archive (name, origin_server, description) "
+ "VALUES ('%s', %s, %s)"
+ % (name, origin_server, description))
+ projectB.query("COMMIT WORK")
+
+def do_architecture():
+ """Initalize the architecture table."""
+
+ projectB.query("BEGIN WORK")
+ projectB.query("DELETE FROM architecture")
+ for arch in Cnf.SubTree("Architectures").List():
+ description = Cnf["Architectures::%s" % (arch)]
+ projectB.query("INSERT INTO architecture (arch_string, description) "
+ "VALUES ('%s', '%s')" % (arch, description))
+ projectB.query("COMMIT WORK")
+
+def do_component():
+ """Initalize the component table."""
+
+ projectB.query("BEGIN WORK")
+ projectB.query("DELETE FROM component")
+ for name in Cnf.SubTree("Component").List():
+ component_config = Cnf.SubTree("Component::%s" % (name))
+ description = sql_get(component_config, "Description")
+ if component_config.get("MeetsDFSG").lower() == "true":
+ meets_dfsg = "true"
+ else:
+ meets_dfsg = "false"
+ projectB.query("INSERT INTO component (name, description, meets_dfsg) "
+ "VALUES ('%s', %s, %s)"
+ % (name, description, meets_dfsg))
+ projectB.query("COMMIT WORK")
+
+def do_location():
+ """Initalize the location table."""
+
+ projectB.query("BEGIN WORK")
+ projectB.query("DELETE FROM location")
+ for location in Cnf.SubTree("Location").List():
+ location_config = Cnf.SubTree("Location::%s" % (location))
+ archive_id = database.get_archive_id(location_config["Archive"])
+ if archive_id == -1:
+ utils.fubar("Archive '%s' for location '%s' not found."
+ % (location_config["Archive"], location))
+ location_type = location_config.get("type")
+ if location_type == "pool":
+ for component in Cnf.SubTree("Component").List():
+ component_id = database.get_component_id(component)
+ projectB.query("INSERT INTO location (path, component, "
+ "archive, type) VALUES ('%s', %d, %d, '%s')"
+ % (location, component_id, archive_id,
+ location_type))
+ else:
+ utils.fubar("E: type '%s' not recognised in location %s."
+ % (location_type, location))
+ projectB.query("COMMIT WORK")
+
+def do_suite():
+ """Initalize the suite table."""
+
+ projectB.query("BEGIN WORK")
+ projectB.query("DELETE FROM suite")
+ for suite in Cnf.SubTree("Suite").List():
+ suite_config = Cnf.SubTree("Suite::%s" %(suite))
+ version = sql_get(suite_config, "Version")
+ origin = sql_get(suite_config, "Origin")
+ description = sql_get(suite_config, "Description")
+ projectB.query("INSERT INTO suite (suite_name, version, origin, "
+ "description) VALUES ('%s', %s, %s, %s)"
+ % (suite.lower(), version, origin, description))
+ for architecture in database.get_suite_architectures(suite):
+ architecture_id = database.get_architecture_id (architecture)
+ if architecture_id < 0:
+ utils.fubar("architecture '%s' not found in architecture"
+ " table for suite %s."