3 # Manipulate suite tags
4 # Copyright (C) 2000 James Troup <james@nocrew.org>
5 # $Id: heidi,v 1.2 2000-12-05 04:27:48 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 # 8to6Guy: "Wow, Bob, You look rough!"
25 # BTAF <.oO>: "You moron! This is what you get for staying up all night drinking vodka and salad dressing!"
26 # BTAF <.oO>: "This coffee I.V. drip is barely even keeping me awake! I need something with more kick! But what?"
27 # BTAF: "OMIGOD! I OVERDOSED ON HEROIN"
28 # CoWorker#n: "Give him air!!"
29 # CoWorker#n+1: "We need a syringe full of adrenaline!"
30 # CoWorker#n+2: "Stab him in the heart!"
32 # CoWorker#n+3: "Bob's been overdosing quite a bit lately..."
33 # CoWorker#n+4: "Third time this week."
35 # -- http://www.angryflower.com/8to6.gif
37 #######################################################################################
39 # Adds or removes packages from a suite. Takes the list of files
40 # either from stdin or as a command line argument. Special action
41 # "set", will reset the suite (!) and add all packages from scratch.
43 #######################################################################################
45 import os, pg, string, sys;
47 import utils, db_access;
49 #######################################################################################
54 #######################################################################################
56 def process_file (file, suite_id, action):
59 projectB.query("DELETE FROM bin_associations WHERE suite = %d" % (suite_id));
60 projectB.query("DELETE FROM src_associations WHERE suite = %d" % (suite_id));
63 for line in file.readlines():
64 split_line = string.split(string.strip(line[:-1]));
65 if len(split_line) != 3:
66 sys.stderr.write("W: '%s' does not break into 'package version architecture'.\n");
69 (package, version, architecture) = split_line;
71 if architecture == "source":
72 q = projectB.query("SELECT id FROM source WHERE source = '%s' AND version = '%s'" % (package, version))
74 q = projectB.query("SELECT b.id FROM binaries b, architecture a WHERE b.package = '%s' AND b.version = '%s' AND (a.arch_string = '%s' OR a.arch_string = 'all') AND b.architecture = a.id" % (package, version, architecture))
78 sys.stderr.write("W: Couldn't find '%s~%s~%s'.\n" % (package, version, architecture));
81 sys.stderr.write("E: Found more than one match for '%s~%s~%s'.\n" % (package, version, architecture));
85 if architecture == "source":
86 # Find the existing assoications ID, if any
87 q = projectB.query("SELECT id FROM src_associations WHERE suite = %d and source = %d" % (suite_id, id));
90 assoication_id = None;
92 assoication_id = ql[0][0];
95 if assoication_id != None:
96 sys.stderr.write("W: '%s~%s~%s' already exists in suite %d.\n" % (package, version, architecture, suite_id));
99 q = projectB.query("INSERT INTO src_associations (suite, source) VALUES (%d, %d)" % (suite_id, id));
100 elif action == "remove":
101 if assoication_id == None:
102 sys.stderr.write("W: '%s~%s~%s' doesn't exist in suite %d.\n" % (package, version, architecture, suite_id));
105 q = projectB.query("DELETE FROM src_associations WHERE id = %d" % (assoication_id));
107 # Find the existing assoications ID, if any
108 q = projectB.query("SELECT id FROM bin_associations WHERE suite = %d and bin = %d" % (suite_id, id));
111 assoication_id = None;
113 assoication_id = ql[0][0];
116 if assoication_id != None:
117 sys.stderr.write("W: '%s~%s~%s' already exists in suite %d.\n" % (package, version, architecture, suite_id));
120 q = projectB.query("INSERT INTO bin_associations (suite, bin) VALUES (%d, %d)" % (suite_id, id));
121 elif action == "remove":
122 if assoication_id == None:
123 sys.stderr.write("W: '%s~%s~%s' doesn't exist in suite %d.\n" % (package, version, architecture, suite_id));
126 q = projectB.query("DELETE FROM bin_associations WHERE id = %d" % (assoication_id));
128 #######################################################################################
130 def get_list (suite_id):
132 q = projectB.query("SELECT b.package, b.version, a.arch_string FROM binaries b, bin_associations ba, architecture a WHERE ba.suite = %d AND ba.bin = b.id AND b.architecture = a.id" % (suite_id));
135 print "%s %s %s" % (i[0], i[1], i[2]);
138 q = projectB.query("SELECT s.source, s.version FROM source s, src_associations sa WHERE sa.suite = %d AND sa.source = s.id" % (suite_id));
141 print "%s %s source" % (i[0], i[1]);
143 #######################################################################################
146 global Cnf, projectB;
150 Cnf = apt_pkg.newConfiguration();
151 apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
153 Arguments = [('a',"add","Heidi::Options::Add", "HasArg"),
154 ('d',"debug","Heidi::Options::Debug", "IntVal"),
155 ('h',"help","Heidi::Options::Help"),
156 ('l',"list","Heidi::Options::List","HasArg"),
157 ('r',"remove", "Heidi::Options::Remove", "HasArg"),
158 ('s',"set", "Heidi::Options::Set", "HasArg"),
159 ('v',"version","Heidi::Options::Version")];
161 file_list = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
163 projectB = pg.connect('projectb', 'localhost');
165 db_access.init(Cnf, projectB);
169 for i in ("add", "list", "remove", "set"):
170 suite = Cnf["Heidi::Options::%s" % (i)];
172 if not Cnf.has_key("Suite::%s" % (suite)):
173 sys.stderr.write("Unknown suite %s.\n" %(suite));
176 suite_id = db_access.get_suite_id(suite);
178 sys.stderr.write("Can only do one action at a time.\n");
184 sys.stderr.write("No action specified.\n");
187 # Safety/Sanity check
188 if action == "set" and suite != "testing":
189 sys.stderr.write("Will not reset a suite other than testing...\n");
196 for file in file_list:
197 process_file(utils.open_file(file_list[0],'r'), suite_id, action);
199 process_file(sys.stdin, suite_id, action);
201 #######################################################################################
203 if __name__ == '__main__':