3 # Sync the ISC configuartion file and the SQL database
4 # Copyright (C) 2000, 2001 James Troup <james@nocrew.org>
5 # $Id: alyson,v 1.6 2001-11-18 19:57:58 rmurray 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 Arguments = [('D',"debug","Alyson::Options::Debug", "IntVal"),
46 ('h',"help","Alyson::Options::Help"),
47 ('v',"version","Alyson::Options::Version")];
48 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
50 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
51 db_access.init(Cnf, projectB);
55 projectB.query("BEGIN WORK");
56 projectB.query("DELETE FROM archive");
57 for name in Cnf.SubTree("Archive").List():
58 Archive = Cnf.SubTree("Archive::%s" % (name));
59 origin_server = get(Archive, "OriginServer");
60 description = get(Archive, "Description");
61 projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description));
62 projectB.query("COMMIT WORK");
66 projectB.query("BEGIN WORK");
67 projectB.query("DELETE FROM architecture");
68 for arch in Cnf.SubTree("Architectures").List():
69 description = Cnf["Architectures::%s" % (arch)];
70 projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description));
71 projectB.query("COMMIT WORK");
75 projectB.query("BEGIN WORK");
76 projectB.query("DELETE FROM component");
77 for name in Cnf.SubTree("Component").List():
78 Component = Cnf.SubTree("Component::%s" % (name));
79 description = get(Component, "Description");
80 if string.lower(Component.get("MeetsDFSG")) == "true":
84 projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
85 projectB.query("COMMIT WORK");
89 projectB.query("BEGIN WORK");
90 projectB.query("DELETE FROM location");
91 for location in Cnf.SubTree("Location").List():
92 Location = Cnf.SubTree("Location::%s" % (location));
93 archive_id = db_access.get_archive_id(Location["Archive"]);
94 type = Location.get("type");
95 if type == "legacy-mixed":
96 projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"]));
97 elif type == "legacy" or type == "pool":
98 for component in Cnf.SubTree("Component").List():
99 component_id = db_access.get_component_id(component);
100 projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
101 (location, component_id, archive_id, type));
103 utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
104 projectB.query("COMMIT WORK");
108 projectB.query("BEGIN WORK");
109 projectB.query("DELETE FROM suite")
110 for suite in Cnf.SubTree("Suite").List():
111 Suite = Cnf.SubTree("Suite::%s" %(suite))
112 version = get(Suite, "Version");
113 origin = get(Suite, "Origin");
114 description = get(Suite, "Description");
115 projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)"
116 % (string.lower(suite), version, origin, description));
117 for architecture in Cnf.SubTree("Suite::%s::Architectures" % (suite)).List():
118 architecture_id = db_access.get_architecture_id (architecture);
119 if architecture_id < 0:
120 utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite));
121 projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id));
122 projectB.query("COMMIT WORK");
126 projectB.query("BEGIN WORK");
127 projectB.query("DELETE FROM override_type");
128 for type in Cnf.SubTree("OverrideType").List():
129 projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type));
130 projectB.query("COMMIT WORK");
134 projectB.query("BEGIN WORK");
135 projectB.query("DELETE FROM priority");
136 for priority in Cnf.SubTree("Priority").List():
137 projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]));
138 projectB.query("COMMIT WORK");
142 projectB.query("BEGIN WORK");
143 projectB.query("DELETE FROM section");
144 for component in Cnf.SubTree("Component").List():
145 if Cnf["Natalie::ComponentPosition"] == "prefix":
147 if component != 'main':
148 prefix = component + '/';
153 component = string.replace(component, "non-US/", "");
154 if component != 'main':
155 suffix = '/' + component;
158 for section in Cnf.SubTree("Section").List():
159 projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix));
160 projectB.query("COMMIT WORK");
162 #######################################################################################
164 if __name__ == '__main__':