]> git.decadent.org.uk Git - dak.git/blob - alyson
Initialize all the tables that are based on the conf file
[dak.git] / alyson
1 #!/usr/bin/env python
2
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 $
6
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.
11
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.
16
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
20
21 ################################################################################
22
23 import pg, sys, string
24 import utils, db_access
25 import apt_pkg;
26
27 ################################################################################
28
29 Cnf = None;
30 projectB = None;
31
32 ################################################################################
33
34 def get (c, i):
35     if c.has_key(i):
36         return "'%s'" % (c[i]);
37     else:
38         return "NULL";
39
40 def main ():
41     global Cnf, projectB;
42
43     apt_pkg.init();
44
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);
51
52     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
53     db_access.init(Cnf, projectB);
54
55     # archive
56
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");
65
66     # architecture
67
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");
74
75     # component
76
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":
83             meets_dfsg = "true";
84         else:
85             meets_dfsg = "false";
86         projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
87     projectB.query("COMMIT WORK");
88
89     # location
90
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));
104         else:
105             utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
106     projectB.query("COMMIT WORK");
107
108     # suite
109
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");
125
126     # override_type
127
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");
133
134     # priority
135
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");
141
142     # section
143
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":
148             suffix = "";
149             if component != 'main':
150                 prefix = component + '/';
151             else:
152                 prefix = "";
153         else:
154             prefix = "";
155             component = string.replace(component, "non-US/", "");
156             if component != 'main':
157                 suffix = '/' + component;
158             else:
159                 suffix = "";
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");
163
164 #######################################################################################
165
166 if __name__ == '__main__':
167     main()
168