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.5 2001-09-27 14:42:02 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]);
45 Cnf = apt_pkg.newConfiguration();
46 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
47 Arguments = [('D',"debug","Alyson::Options::Debug", "IntVal"),
48 ('h',"help","Alyson::Options::Help"),
49 ('v',"version","Alyson::Options::Version")];
50 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
52 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
53 db_access.init(Cnf, projectB);
57 projectB.query("BEGIN WORK");
58 projectB.query("DELETE FROM archive");
59 for name in Cnf.SubTree("Archive").List():
60 Archive = Cnf.SubTree("Archive::%s" % (name));
61 origin_server = get(Archive, "OriginServer");
62 description = get(Archive, "Description");
63 projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description));
64 projectB.query("COMMIT WORK");
68 projectB.query("BEGIN WORK");
69 projectB.query("DELETE FROM architecture");
70 for arch in Cnf.SubTree("Architectures").List():
71 description = Cnf["Architectures::%s" % (arch)];
72 projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description));
73 projectB.query("COMMIT WORK");
77 projectB.query("BEGIN WORK");
78 projectB.query("DELETE FROM component");
79 for name in Cnf.SubTree("Component").List():
80 Component = Cnf.SubTree("Component::%s" % (name));
81 description = get(Component, "Description");
82 if string.lower(Component.get("MeetsDFSG")) == "true":
86 projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
87 projectB.query("COMMIT WORK");
91 projectB.query("BEGIN WORK");
92 projectB.query("DELETE FROM location");
93 for location in Cnf.SubTree("Location").List():
94 Location = Cnf.SubTree("Location::%s" % (location));
95 archive_id = db_access.get_archive_id(Location["Archive"]);
96 type = Location.get("type");
97 if type == "legacy-mixed":
98 projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"]));
99 elif type == "legacy" or type == "pool":
100 for component in Cnf.SubTree("Component").List():
101 component_id = db_access.get_component_id(component);
102 projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
103 (location, component_id, archive_id, type));
105 utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
106 projectB.query("COMMIT WORK");
110 projectB.query("BEGIN WORK");
111 projectB.query("DELETE FROM suite")
112 for suite in Cnf.SubTree("Suite").List():
113 Suite = Cnf.SubTree("Suite::%s" %(suite))
114 version = get(Suite, "Version");
115 origin = get(Suite, "Origin");
116 description = get(Suite, "Description");
117 projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)"
118 % (string.lower(suite), version, origin, description));
119 for architecture in Cnf.SubTree("Suite::%s::Architectures" % (suite)).List():
120 architecture_id = db_access.get_architecture_id (architecture);
121 if architecture_id < 0:
122 utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite));
123 projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id));
124 projectB.query("COMMIT WORK");
128 projectB.query("BEGIN WORK");
129 projectB.query("DELETE FROM override_type");
130 for type in Cnf.SubTree("OverrideType").List():
131 projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type));
132 projectB.query("COMMIT WORK");
136 projectB.query("BEGIN WORK");
137 projectB.query("DELETE FROM priority");
138 for priority in Cnf.SubTree("Priority").List():
139 projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]));
140 projectB.query("COMMIT WORK");
144 projectB.query("BEGIN WORK");
145 projectB.query("DELETE FROM section");
146 for component in Cnf.SubTree("Component").List():
147 if Cnf["Natalie::ComponentPosition"] == "prefix":
149 if component != 'main':
150 prefix = component + '/';
155 component = string.replace(component, "non-US/", "");
156 if component != 'main':
157 suffix = '/' + component;
160 for section in Cnf.SubTree("Section").List():
161 projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix));
162 projectB.query("COMMIT WORK");
164 #######################################################################################
166 if __name__ == '__main__':