3 # Sync the ISC configuartion file and the SQL database
4 # Copyright (C) 2000, 2001, 2002, 2003 James Troup <james@nocrew.org>
5 # $Id: alyson,v 1.12 2003-09-07 13:52:07 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 ################################################################################
24 import utils, db_access;
27 ################################################################################
32 ################################################################################
34 def usage(exit_code=0):
35 print """Usage: alyson
36 Initalizes some tables in the projectB database based on the config file.
38 -h, --help show this help and exit."""
41 ################################################################################
45 return "'%s'" % (c[i]);
52 Cnf = utils.get_conf()
53 Arguments = [('h',"help","Alyson::Options::Help")];
55 if not Cnf.has_key("Alyson::Options::%s" % (i)):
56 Cnf["Alyson::Options::%s" % (i)] = "";
58 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
60 Options = Cnf.SubTree("Alyson::Options")
64 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
65 db_access.init(Cnf, projectB);
69 projectB.query("BEGIN WORK");
70 projectB.query("DELETE FROM archive");
71 for name in Cnf.SubTree("Archive").List():
72 Archive = Cnf.SubTree("Archive::%s" % (name));
73 origin_server = get(Archive, "OriginServer");
74 description = get(Archive, "Description");
75 projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description));
76 projectB.query("COMMIT WORK");
80 projectB.query("BEGIN WORK");
81 projectB.query("DELETE FROM architecture");
82 for arch in Cnf.SubTree("Architectures").List():
83 description = Cnf["Architectures::%s" % (arch)];
84 projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description));
85 projectB.query("COMMIT WORK");
89 projectB.query("BEGIN WORK");
90 projectB.query("DELETE FROM component");
91 for name in Cnf.SubTree("Component").List():
92 Component = Cnf.SubTree("Component::%s" % (name));
93 description = get(Component, "Description");
94 if Component.get("MeetsDFSG").lower() == "true":
98 projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
99 projectB.query("COMMIT WORK");
103 projectB.query("BEGIN WORK");
104 projectB.query("DELETE FROM location");
105 for location in Cnf.SubTree("Location").List():
106 Location = Cnf.SubTree("Location::%s" % (location));
107 archive_id = db_access.get_archive_id(Location["Archive"]);
108 type = Location.get("type");
109 if type == "legacy-mixed":
110 projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"]));
111 elif type == "legacy" or type == "pool":
112 for component in Cnf.SubTree("Component").List():
113 component_id = db_access.get_component_id(component);
114 projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
115 (location, component_id, archive_id, type));
117 utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
118 projectB.query("COMMIT WORK");
122 projectB.query("BEGIN WORK");
123 projectB.query("DELETE FROM suite")
124 for suite in Cnf.SubTree("Suite").List():
125 Suite = Cnf.SubTree("Suite::%s" %(suite))
126 version = get(Suite, "Version");
127 origin = get(Suite, "Origin");
128 description = get(Suite, "Description");
129 projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)"
130 % (suite.lower(), version, origin, description));
131 for architecture in Cnf.ValueList("Suite::%s::Architectures" % (suite)):
132 architecture_id = db_access.get_architecture_id (architecture);
133 if architecture_id < 0:
134 utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite));
135 projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id));
136 projectB.query("COMMIT WORK");
140 projectB.query("BEGIN WORK");
141 projectB.query("DELETE FROM override_type");
142 for type in Cnf.ValueList("OverrideType"):
143 projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type));
144 projectB.query("COMMIT WORK");
148 projectB.query("BEGIN WORK");
149 projectB.query("DELETE FROM priority");
150 for priority in Cnf.SubTree("Priority").List():
151 projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]));
152 projectB.query("COMMIT WORK");
156 projectB.query("BEGIN WORK");
157 projectB.query("DELETE FROM section");
158 for component in Cnf.SubTree("Component").List():
159 if Cnf["Natalie::ComponentPosition"] == "prefix":
161 if component != "main":
162 prefix = component + '/';
167 component = component.replace("non-US/", "");
168 if component != "main":
169 suffix = '/' + component;
172 for section in Cnf.ValueList("Section"):
173 projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix));
174 projectB.query("COMMIT WORK");
176 ################################################################################
178 if __name__ == '__main__':