3 # Microscopic modification and query tool for overrides in projectb
4 # Copyright (C) 2004 Daniel Silverstone <dsilvers@digital-scurf.org>
5 # $Id: alicia,v 1.4 2004-03-11 00:08:32 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
22 ################################################################################
23 ## So line up your soldiers and she'll shoot them all down
24 ## Coz Alisha Rules The World
25 ## You think you found a dream, then it shatters and it seems,
26 ## That Alisha Rules The World
27 ################################################################################
30 import utils, db_access;
31 import apt_pkg, logging;
33 ################################################################################
38 ################################################################################
40 # Shamelessly stolen from melanie. Should probably end up in utils.py
42 answer = utils.our_raw_input("Continue (y/N)? ").lower();
48 def usage (exit_code=0):
49 print """Usage: alicia [OPTIONS] package [section] [priority]
50 Make microchanges or microqueries of the overrides
52 -h, --help show this help and exit
53 -d, --done=BUG# send priority/section change as closure to bug#
54 -n, --no-action don't do anything
55 -s, --suite specify the suite to use
62 Cnf = utils.get_conf()
64 Arguments = [('h',"help","Alicia::Options::Help"),
65 ('d',"done","Alicia::Options::Done", "HasArg"),
66 ('n',"no-action","Alicia::Options::No-Action"),
67 ('s',"suite","Alicia::Options::Suite", "HasArg"),
69 for i in ["help", "no-action"]:
70 if not Cnf.has_key("Alicia::Options::%s" % (i)):
71 Cnf["Alicia::Options::%s" % (i)] = "";
72 if not Cnf.has_key("Alicia::Options::Suite"):
73 Cnf["Alicia::Options::Suite"] = "unstable";
75 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
76 Options = Cnf.SubTree("Alicia::Options")
81 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
82 db_access.init(Cnf, projectB);
85 utils.fubar("package name is a required argument.");
87 package = arguments.pop(0);
88 suite = Options["Suite"]
89 if arguments and len(arguments) > 2:
90 utils.fubar("Too many arguments");
92 if arguments and len(arguments) == 1:
93 # Determine if the argument is a priority or a section...
94 arg = arguments.pop();
95 q = projectB.query("""
96 SELECT ( SELECT COUNT(*) FROM section WHERE section=%s ) AS secs,
97 ( SELECT COUNT(*) FROM priority WHERE priority=%s ) AS prios
98 """ % ( pg._quote(arg,"str"), pg._quote(arg,"str")));
101 arguments = (arg,".");
103 arguments = (".",arg);
105 utils.fubar("%s is not a valid section or priority" % (arg));
108 # Retrieve current section/priority...
109 q = projectB.query("""
110 SELECT priority.priority AS prio, section.section AS sect
111 FROM override, priority, section, suite
112 WHERE override.priority = priority.id
113 AND override.section = section.id
114 AND override.package = %s
115 AND override.suite = suite.id
116 AND suite.suite_name = %s
117 """ % (pg._quote(package,"str"), pg._quote(suite,"str")));
120 utils.fubar("Unable to find package %s" % (package));
122 utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()));
125 oldsection = r[0][1];
126 oldpriority = r[0][0];
129 print "%s is in section '%s' at priority '%s'" % (
130 package,oldsection,oldpriority);
133 # At this point, we have a new section and priority... check they're valid...
134 newsection, newpriority = arguments;
136 if newsection == ".":
137 newsection = oldsection;
138 if newpriority == ".":
139 newpriority = oldpriority;
141 q = projectB.query("SELECT id FROM section WHERE section=%s" % (
142 pg._quote(newsection,"str")));
145 utils.fubar("Supplied section %s is invalid" % (newsection));
146 newsecid = q.getresult()[0][0];
148 q = projectB.query("SELECT id FROM priority WHERE priority=%s" % (
149 pg._quote(newpriority,"str")));
152 utils.fubar("Supplied priority %s is invalid" % (newpriority));
153 newprioid = q.getresult()[0][0];
155 if newpriority == oldpriority and newsection == oldsection:
156 print "I: Doing nothing"
159 # If we're in no-action mode
160 if Options["No-Action"]:
161 if newpriority != oldpriority:
162 print "I: Would change priority from %s to %s" % (oldpriority,newpriority);
163 if newsection != oldsection:
164 print "I: Would change section from %s to %s" % (oldsection,newsection);
165 if Options.has_key("Done"):
166 print "I: Would also close bug(s): %s" % (Options["Done"]);
170 if newpriority != oldpriority:
171 print "I: Will change priority from %s to %s" % (oldpriority,newpriority);
172 if newsection != oldsection:
173 print "I: Will change section from %s to %s" % (oldsection,newsection);
175 if not Options.has_key("Done"):
176 #utils.warn("No bugs to close have been specified. Noone will know you have done this.");
178 print "I: Will close bug(s): %s" % (Options["Done"]);
182 Logger = logging.Logger(Cnf, "alicia");
184 projectB.query("BEGIN WORK");
185 # We're in "do it" mode, we have something to do... do it
186 if newpriority != oldpriority:
187 q = projectB.query("""
191 AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
193 pg._quote(package,"str"),
194 pg._quote(suite,"str") ));
195 Logger.log(["changed priority",package,oldpriority,newpriority]);
197 if newsection != oldsection:
198 q = projectB.query("""
202 AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
204 pg._quote(package,"str"),
205 pg._quote(suite,"str") ));
206 Logger.log(["changed priority",package,oldsection,newsection]);
207 projectB.query("COMMIT WORK");
209 if Options.has_key("Done"):
211 Subst["__ALICIA_ADDRESS__"] = Cnf["Alicia::MyEmailAddress"];
212 Subst["__BUG_SERVER__"] = Cnf["Dinstall::BugServer"];
214 if Cnf.Find("Dinstall::Bcc") != "":
215 bcc.append(Cnf["Dinstall::Bcc"]);
216 if Cnf.Find("Alicia::Bcc") != "":
217 bcc.append(Cnf["Alicia::Bcc"]);
219 Subst["__BCC__"] = "Bcc: " + ", ".join(bcc);
221 Subst["__BCC__"] = "X-Filler: 42";
222 Subst["__CC__"] = "X-Katie: alicia $Revision: 1.4 $";
223 Subst["__ADMIN_ADDRESS__"] = Cnf["Dinstall::MyAdminAddress"];
224 Subst["__DISTRO__"] = Cnf["Dinstall::MyDistribution"];
225 Subst["__WHOAMI__"] = utils.whoami();
227 summary = "Concerning package %s...\n" % (package);
228 summary += "Operating on the %s suite\n" % (suite);
229 if newpriority != oldpriority:
230 summary += "Changed priority from %s to %s\n" % (oldpriority,newpriority);
231 if newsection != oldsection:
232 summary += "Changed section from %s to %s\n" % (oldsection,newsection);
233 Subst["__SUMMARY__"] = summary;
235 for bug in utils.split_args(Options["Done"]):
236 Subst["__BUG_NUMBER__"] = bug;
237 mail_message = utils.TemplateSubst(
238 Subst,Cnf["Dir::Templates"]+"/alicia.bug-close");
239 utils.send_mail(mail_message);
240 Logger.log(["closed bug",bug]);
246 #################################################################################
248 if __name__ == '__main__':