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.2 2004-01-29 10:40:18 dsilvers 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 -n, --no-action don't do anything
54 -s, --suite specify the suite to use
61 Cnf = utils.get_conf()
63 Arguments = [('h',"help","Alicia::Options::Help"),
64 ('n',"no-action","Alicia::Options::No-Action"),
65 ('s',"suite","Alicia::Options::Suite", "HasArg"),
67 for i in ["help", "no-action"]:
68 if not Cnf.has_key("Alicia::Options::%s" % (i)):
69 Cnf["Alicia::Options::%s" % (i)] = "";
70 if not Cnf.has_key("Alicia::Options::Suite"):
71 Cnf["Alicia::Options::Suite"] = "unstable";
73 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
74 Options = Cnf.SubTree("Alicia::Options")
79 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
80 db_access.init(Cnf, projectB);
83 utils.fubar("package name is a required argument.");
85 package = arguments.pop(0);
87 if arguments and len(arguments) > 2:
88 utils.fubar("Too many arguments");
90 if arguments and len(arguments) == 1:
91 # Determine if the argument is a priority or a section...
92 arg = arguments.pop();
93 q = projectB.query("""
94 SELECT ( SELECT COUNT(*) FROM section WHERE section=%s ) AS secs,
95 ( SELECT COUNT(*) FROM priority WHERE priority=%s ) AS prios
96 """ % ( pg._quote(arg,"str"), pg._quote(arg,"str")));
99 arguments = (arg,".");
101 arguments = (".",arg);
103 utils.fubar("%s is not a valid section or priority" % (arg));
106 # Retrieve current section/priority...
107 q = projectB.query("""
108 SELECT priority.priority AS prio, section.section AS sect
109 FROM override, priority, section, suite
110 WHERE override.priority = priority.id
111 AND override.section = section.id
112 AND override.package = %s
113 AND override.suite = suite.id
114 AND suite.suite_name = %s
115 """ % (pg._quote(package,"str"), pg._quote(Options["Suite"],"str")));
118 utils.fubar("Unable to find package %s" % (package));
120 utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()));
123 oldsection = r[0][1];
124 oldpriority = r[0][0];
127 print "%s is in section '%s' at priority '%s'" % (
128 package,oldsection,oldpriority);
131 # At this point, we have a new section and priority... check they're valid...
132 newsection, newpriority = arguments;
134 if newsection == ".":
135 newsection = oldsection;
136 if newpriority == ".":
137 newpriority = oldpriority;
139 q = projectB.query("SELECT id FROM section WHERE section=%s" % (
140 pg._quote(newsection,"str")));
143 utils.fubar("Supplied section %s is invalid" % (newsection));
144 newsecid = q.getresult()[0][0];
146 q = projectB.query("SELECT id FROM priority WHERE priority=%s" % (
147 pg._quote(newpriority,"str")));
150 utils.fubar("Supplied priority %s is invalid" % (newpriority));
151 newprioid = q.getresult()[0][0];
153 if newpriority == oldpriority and newsection == oldsection:
154 print "I: Doing nothing"
157 # If we're in no-action mode
158 if Options["No-Action"]:
159 if newpriority != oldpriority:
160 print "I: Would change priority from %s to %s" % (oldpriority,newpriority);
161 if newsection != oldsection:
162 print "I: Would change section from %s to %s" % (oldsection,newsection);
165 if newpriority != oldpriority:
166 print "I: Will change priority from %s to %s" % (oldpriority,newpriority);
167 if newsection != oldsection:
168 print "I: Will change section from %s to %s" % (oldsection,newsection);
172 Logger = logging.Logger(Cnf, "alicia");
174 projectB.query("BEGIN WORK");
175 # We're in "do it" mode, we have something to do... do it
176 if newpriority != oldpriority:
177 q = projectB.query("""
181 AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
183 pg._quote(package,"str"),
184 pg._quote(Options["Suite"],"str") ));
185 Logger.log(["changed priority",package,oldpriority,newpriority]);
187 if newsection != oldsection:
188 q = projectB.query("""
192 AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
194 pg._quote(package,"str"),
195 pg._quote(Options["Suite"],"str") ));
196 Logger.log(["changed priority",package,oldsection,newsection]);
197 projectB.query("COMMIT WORK");
203 #################################################################################
205 if __name__ == '__main__':