]> git.decadent.org.uk Git - dak.git/blob - alyson
read all configs when utils is imported, allowing utils to make use ofconfig values...
[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.6 2001-11-18 19:57:58 rmurray 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     Cnf = utils.get_conf()
44
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);
49
50     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
51     db_access.init(Cnf, projectB);
52
53     # archive
54
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");
63
64     # architecture
65
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");
72
73     # component
74
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":
81             meets_dfsg = "true";
82         else:
83             meets_dfsg = "false";
84         projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
85     projectB.query("COMMIT WORK");
86
87     # location
88
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));
102         else:
103             utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
104     projectB.query("COMMIT WORK");
105
106     # suite
107
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");
123
124     # override_type
125
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");
131
132     # priority
133
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");
139
140     # section
141
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":
146             suffix = "";
147             if component != 'main':
148                 prefix = component + '/';
149             else:
150                 prefix = "";
151         else:
152             prefix = "";
153             component = string.replace(component, "non-US/", "");
154             if component != 'main':
155                 suffix = '/' + component;
156             else:
157                 suffix = "";
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");
161
162 #######################################################################################
163
164 if __name__ == '__main__':
165     main()
166