3 # Sync the ISC configuartion file and the SQL database
4 # Copyright (C) 2000, 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: alyson,v 1.9 2002-05-14 15:28:53 troup Exp $
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
23 import pg, sys, string
24 import utils, db_access
27 ################################################################################
32 ################################################################################
36 return "'%s'" % (c[i]);
43 Cnf = utils.get_conf()
45 apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
47 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
48 db_access.init(Cnf, projectB);
52 projectB.query("BEGIN WORK");
53 projectB.query("DELETE FROM archive");
54 for name in Cnf.SubTree("Archive").List():
55 Archive = Cnf.SubTree("Archive::%s" % (name));
56 origin_server = get(Archive, "OriginServer");
57 description = get(Archive, "Description");
58 projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description));
59 projectB.query("COMMIT WORK");
63 projectB.query("BEGIN WORK");
64 projectB.query("DELETE FROM architecture");
65 for arch in Cnf.SubTree("Architectures").List():
66 description = Cnf["Architectures::%s" % (arch)];
67 projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description));
68 projectB.query("COMMIT WORK");
72 projectB.query("BEGIN WORK");
73 projectB.query("DELETE FROM component");
74 for name in Cnf.SubTree("Component").List():
75 Component = Cnf.SubTree("Component::%s" % (name));
76 description = get(Component, "Description");
77 if string.lower(Component.get("MeetsDFSG")) == "true":
81 projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
82 projectB.query("COMMIT WORK");
86 projectB.query("BEGIN WORK");
87 projectB.query("DELETE FROM location");
88 for location in Cnf.SubTree("Location").List():
89 Location = Cnf.SubTree("Location::%s" % (location));
90 archive_id = db_access.get_archive_id(Location["Archive"]);
91 type = Location.get("type");
92 if type == "legacy-mixed":
93 projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"]));
94 elif type == "legacy" or type == "pool":
95 for component in Cnf.SubTree("Component").List():
96 component_id = db_access.get_component_id(component);
97 projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
98 (location, component_id, archive_id, type));
100 utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
101 projectB.query("COMMIT WORK");
105 projectB.query("BEGIN WORK");
106 projectB.query("DELETE FROM suite")
107 for suite in Cnf.SubTree("Suite").List():
108 Suite = Cnf.SubTree("Suite::%s" %(suite))
109 version = get(Suite, "Version");
110 origin = get(Suite, "Origin");
111 description = get(Suite, "Description");
112 projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)"
113 % (string.lower(suite), version, origin, description));
114 for architecture in Cnf.ValueList("Suite::%s::Architectures" % (suite)):
115 architecture_id = db_access.get_architecture_id (architecture);
116 if architecture_id < 0:
117 utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite));
118 projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id));
119 projectB.query("COMMIT WORK");
123 projectB.query("BEGIN WORK");
124 projectB.query("DELETE FROM override_type");
125 for type in Cnf.ValueList("OverrideType"):
126 projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type));
127 projectB.query("COMMIT WORK");
131 projectB.query("BEGIN WORK");
132 projectB.query("DELETE FROM priority");
133 for priority in Cnf.SubTree("Priority").List():
134 projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]));
135 projectB.query("COMMIT WORK");
139 projectB.query("BEGIN WORK");
140 projectB.query("DELETE FROM section");
141 for component in Cnf.SubTree("Component").List():
142 if Cnf["Natalie::ComponentPosition"] == "prefix":
144 if component != 'main':
145 prefix = component + '/';
150 component = string.replace(component, "non-US/", "");
151 if component != 'main':
152 suffix = '/' + component;
155 for section in Cnf.ValueList("Section"):
156 projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix));
157 projectB.query("COMMIT WORK");
159 #######################################################################################
161 if __name__ == '__main__':