3 # Microscopic modification and query tool for overrides in projectb
4 # Copyright (C) 2004, 2006 Daniel Silverstone <dsilvers@digital-scurf.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
22 ## So line up your soldiers and she'll shoot them all down
23 ## Coz Alisha Rules The World
24 ## You think you found a dream, then it shatters and it seems,
25 ## That Alisha Rules The World
26 ################################################################################
29 import dak.lib.utils, dak.lib.database
30 import apt_pkg, dak.lib.logging
32 ################################################################################
37 ################################################################################
39 # Shamelessly stolen from 'dak rm'. Should probably end up in dak.lib.utils.py
41 answer = dak.lib.utils.our_raw_input("Continue (y/N)? ").lower()
47 def usage (exit_code=0):
48 print """Usage: dak override [OPTIONS] package [section] [priority]
49 Make microchanges or microqueries of the overrides
51 -h, --help show this help and exit
52 -d, --done=BUG# send priority/section change as closure to bug#
53 -n, --no-action don't do anything
54 -s, --suite specify the suite to use
61 Cnf = dak.lib.utils.get_conf()
63 Arguments = [('h',"help","Override::Options::Help"),
64 ('d',"done","Override::Options::Done", "HasArg"),
65 ('n',"no-action","Override::Options::No-Action"),
66 ('s',"suite","Override::Options::Suite", "HasArg"),
68 for i in ["help", "no-action"]:
69 if not Cnf.has_key("Override::Options::%s" % (i)):
70 Cnf["Override::Options::%s" % (i)] = ""
71 if not Cnf.has_key("Override::Options::Suite"):
72 Cnf["Override::Options::Suite"] = "unstable"
74 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
75 Options = Cnf.SubTree("Override::Options")
80 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
81 dak.lib.database.init(Cnf, projectB)
84 dak.lib.utils.fubar("package name is a required argument.")
86 package = arguments.pop(0)
87 suite = Options["Suite"]
88 if arguments and len(arguments) > 2:
89 dak.lib.utils.fubar("Too many arguments")
91 if arguments and len(arguments) == 1:
92 # Determine if the argument is a priority or a section...
94 q = projectB.query("""
95 SELECT ( SELECT COUNT(*) FROM section WHERE section=%s ) AS secs,
96 ( SELECT COUNT(*) FROM priority WHERE priority=%s ) AS prios
97 """ % ( pg._quote(arg,"str"), pg._quote(arg,"str")))
100 arguments = (arg,".")
102 arguments = (".",arg)
104 dak.lib.utils.fubar("%s is not a valid section or priority" % (arg))
107 # Retrieve current section/priority...
108 q = projectB.query("""
109 SELECT priority.priority AS prio, section.section AS sect
110 FROM override, priority, section, suite
111 WHERE override.priority = priority.id
112 AND override.section = section.id
113 AND override.package = %s
114 AND override.suite = suite.id
115 AND suite.suite_name = %s
116 """ % (pg._quote(package,"str"), pg._quote(suite,"str")))
119 dak.lib.utils.fubar("Unable to find package %s" % (package))
121 dak.lib.utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()))
125 oldpriority = r[0][0]
128 print "%s is in section '%s' at priority '%s'" % (
129 package,oldsection,oldpriority)
132 # At this point, we have a new section and priority... check they're valid...
133 newsection, newpriority = arguments
135 if newsection == ".":
136 newsection = oldsection
137 if newpriority == ".":
138 newpriority = oldpriority
140 q = projectB.query("SELECT id FROM section WHERE section=%s" % (
141 pg._quote(newsection,"str")))
144 dak.lib.utils.fubar("Supplied section %s is invalid" % (newsection))
145 newsecid = q.getresult()[0][0]
147 q = projectB.query("SELECT id FROM priority WHERE priority=%s" % (
148 pg._quote(newpriority,"str")))
151 dak.lib.utils.fubar("Supplied priority %s is invalid" % (newpriority))
152 newprioid = q.getresult()[0][0]
154 if newpriority == oldpriority and newsection == oldsection:
155 print "I: Doing nothing"
158 # If we're in no-action mode
159 if Options["No-Action"]:
160 if newpriority != oldpriority:
161 print "I: Would change priority from %s to %s" % (oldpriority,newpriority)
162 if newsection != oldsection:
163 print "I: Would change section from %s to %s" % (oldsection,newsection)
164 if Options.has_key("Done"):
165 print "I: Would also close bug(s): %s" % (Options["Done"])
169 if newpriority != oldpriority:
170 print "I: Will change priority from %s to %s" % (oldpriority,newpriority)
171 if newsection != oldsection:
172 print "I: Will change section from %s to %s" % (oldsection,newsection)
174 if not Options.has_key("Done"):
176 #dak.lib.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 = dak.lib.logging.Logger(Cnf, "override")
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["__OVERRIDE_ADDRESS__"] = Cnf["Override::MyEmailAddress"]
212 Subst["__BUG_SERVER__"] = Cnf["Dinstall::BugServer"]
214 if Cnf.Find("Dinstall::Bcc") != "":
215 bcc.append(Cnf["Dinstall::Bcc"])
216 if Cnf.Find("Override::Bcc") != "":
217 bcc.append(Cnf["Override::Bcc"])
219 Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
221 Subst["__BCC__"] = "X-Filler: 42"
222 Subst["__CC__"] = "X-DAK: dak override"
223 Subst["__ADMIN_ADDRESS__"] = Cnf["Dinstall::MyAdminAddress"]
224 Subst["__DISTRO__"] = Cnf["Dinstall::MyDistribution"]
225 Subst["__WHOAMI__"] = dak.lib.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 dak.lib.utils.split_args(Options["Done"]):
236 Subst["__BUG_NUMBER__"] = bug
237 mail_message = dak.lib.utils.TemplateSubst(
238 Subst,Cnf["Dir::Templates"]+"/override.bug-close")
239 dak.lib.utils.send_mail(mail_message)
240 Logger.log(["closed bug",bug])
246 #################################################################################
248 if __name__ == '__main__':