]> git.decadent.org.uk Git - dak.git/blob - alyson
Update copyright
[dak.git] / alyson
1 #!/usr/bin/env python
2
3 # Sync the ISC configuartion file and the SQL database
4 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: alyson,v 1.8 2002-05-03 16:06:45 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     Cnf = utils.get_conf()
44
45     apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
46
47     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
48     db_access.init(Cnf, projectB);
49
50     # archive
51
52     projectB.query("BEGIN WORK");
53     projectB.query("DELETE FROM archive");
54     for name in Cnf.SubTree("Archive").List():
55         Archive = Cnf.SubTree("Archive::%s" % (name));
56         origin_server = get(Archive, "OriginServer");
57         description = get(Archive, "Description");
58         projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', %s, %s)" % (name, origin_server, description));
59     projectB.query("COMMIT WORK");
60
61     # architecture
62
63     projectB.query("BEGIN WORK");
64     projectB.query("DELETE FROM architecture");
65     for arch in Cnf.SubTree("Architectures").List():
66         description = Cnf["Architectures::%s" % (arch)];
67         projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, description));
68     projectB.query("COMMIT WORK");
69
70     # component
71
72     projectB.query("BEGIN WORK");
73     projectB.query("DELETE FROM component");
74     for name in Cnf.SubTree("Component").List():
75         Component = Cnf.SubTree("Component::%s" % (name));
76         description = get(Component, "Description");
77         if string.lower(Component.get("MeetsDFSG")) == "true":
78             meets_dfsg = "true";
79         else:
80             meets_dfsg = "false";
81         projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', %s, %s)" % (name, description, meets_dfsg));
82     projectB.query("COMMIT WORK");
83
84     # location
85
86     projectB.query("BEGIN WORK");
87     projectB.query("DELETE FROM location");
88     for location in Cnf.SubTree("Location").List():
89         Location = Cnf.SubTree("Location::%s" % (location));
90         archive_id = db_access.get_archive_id(Location["Archive"]);
91         type = Location.get("type");
92         if type == "legacy-mixed":
93             projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, Location["type"]));
94         elif type == "legacy" or type == "pool":
95             for component in Cnf.SubTree("Component").List():
96                 component_id = db_access.get_component_id(component);
97                 projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
98                                (location, component_id, archive_id, type));
99         else:
100             utils.fubar("E: type '%s' not recognised in location %s." % (type, location));
101     projectB.query("COMMIT WORK");
102
103     # suite
104
105     projectB.query("BEGIN WORK");
106     projectB.query("DELETE FROM suite")
107     for suite in Cnf.SubTree("Suite").List():
108         Suite = Cnf.SubTree("Suite::%s" %(suite))
109         version = get(Suite, "Version");
110         origin = get(Suite, "Origin");
111         description = get(Suite, "Description");
112         projectB.query("INSERT INTO suite (suite_name, version, origin, description) VALUES ('%s', %s, %s, %s)"
113                        % (string.lower(suite), version, origin, description));
114         for architecture in Cnf.SubTree("Suite::%s::Architectures" % (suite)).List():
115             architecture_id = db_access.get_architecture_id (architecture);
116             if architecture_id < 0:
117                 utils.fubar("architecture '%s' not found in architecture table for suite %s." % (architecture, suite));
118             projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id));
119     projectB.query("COMMIT WORK");
120
121     # override_type
122
123     projectB.query("BEGIN WORK");
124     projectB.query("DELETE FROM override_type");
125     for type in Cnf.SubTree("OverrideType").List():
126         projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type));
127     projectB.query("COMMIT WORK");
128
129     # priority
130
131     projectB.query("BEGIN WORK");
132     projectB.query("DELETE FROM priority");
133     for priority in Cnf.SubTree("Priority").List():
134         projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]));
135     projectB.query("COMMIT WORK");
136
137     # section
138
139     projectB.query("BEGIN WORK");
140     projectB.query("DELETE FROM section");
141     for component in Cnf.SubTree("Component").List():
142         if Cnf["Natalie::ComponentPosition"] == "prefix":
143             suffix = "";
144             if component != 'main':
145                 prefix = component + '/';
146             else:
147                 prefix = "";
148         else:
149             prefix = "";
150             component = string.replace(component, "non-US/", "");
151             if component != 'main':
152                 suffix = '/' + component;
153             else:
154                 suffix = "";
155         for section in Cnf.SubTree("Section").List():
156             projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix));
157     projectB.query("COMMIT WORK");
158
159 #######################################################################################
160
161 if __name__ == '__main__':
162     main()
163