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 ################################################################################
31 import daklib.database
34 ################################################################################
39 ################################################################################
41 # Shamelessly stolen from 'dak rm'. Should probably end up in daklib.utils.py
43 answer = daklib.utils.our_raw_input("Continue (y/N)? ").lower()
49 def usage (exit_code=0):
50 print """Usage: dak override [OPTIONS] package [section] [priority]
51 Make microchanges or microqueries of the binary overrides
53 -h, --help show this help and exit
54 -d, --done=BUG# send priority/section change as closure to bug#
55 -n, --no-action don't do anything
56 -s, --suite specify the suite to use
63 Cnf = daklib.utils.get_conf()
65 Arguments = [('h',"help","Override::Options::Help"),
66 ('d',"done","Override::Options::Done", "HasArg"),
67 ('n',"no-action","Override::Options::No-Action"),
68 ('s',"suite","Override::Options::Suite", "HasArg"),
70 for i in ["help", "no-action"]:
71 if not Cnf.has_key("Override::Options::%s" % (i)):
72 Cnf["Override::Options::%s" % (i)] = ""
73 if not Cnf.has_key("Override::Options::Suite"):
74 Cnf["Override::Options::Suite"] = "unstable"
76 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
77 Options = Cnf.SubTree("Override::Options")
82 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
83 daklib.database.init(Cnf, projectB)
86 daklib.utils.fubar("package name is a required argument.")
88 package = arguments.pop(0)
89 suite = Options["Suite"]
90 if arguments and len(arguments) > 2:
91 daklib.utils.fubar("Too many arguments")
93 if arguments and len(arguments) == 1:
94 # Determine if the argument is a priority or a section...
96 q = projectB.query("""
97 SELECT ( SELECT COUNT(*) FROM section WHERE section=%s ) AS secs,
98 ( SELECT COUNT(*) FROM priority WHERE priority=%s ) AS prios
99 """ % ( pg._quote(arg,"str"), pg._quote(arg,"str")))
102 arguments = (arg,".")
104 arguments = (".",arg)
106 daklib.utils.fubar("%s is not a valid section or priority" % (arg))
108 # Retrieve current section/priority...
109 # TODO: fetch dsc records and update them too, if needed.
110 q = projectB.query("""
111 SELECT priority.priority AS prio, section.section AS sect, override_type.type AS type
112 FROM override, priority, section, suite, override_type
113 WHERE override.priority = priority.id
114 AND override.type = override_type.id
115 AND override_type.type != 'dsc'
116 AND override.section = section.id
117 AND override.package = %s
118 AND override.suite = suite.id
119 AND suite.suite_name = %s
120 """ % (pg._quote(package,"str"), pg._quote(suite,"str")))
123 daklib.utils.fubar("Unable to find package %s" % (package))
125 daklib.utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()))
129 oldpriority = r[0][0]
132 print "%s is in section '%s' at priority '%s'" % (
133 package,oldsection,oldpriority)
136 # At this point, we have a new section and priority... check they're valid...
137 newsection, newpriority = arguments
139 if newsection == ".":
140 newsection = oldsection
141 if newpriority == ".":
142 newpriority = oldpriority
144 q = projectB.query("SELECT id FROM section WHERE section=%s" % (
145 pg._quote(newsection,"str")))
148 daklib.utils.fubar("Supplied section %s is invalid" % (newsection))
149 newsecid = q.getresult()[0][0]
151 q = projectB.query("SELECT id FROM priority WHERE priority=%s" % (
152 pg._quote(newpriority,"str")))
155 daklib.utils.fubar("Supplied priority %s is invalid" % (newpriority))
156 newprioid = q.getresult()[0][0]
158 if newpriority == oldpriority and newsection == oldsection:
159 print "I: Doing nothing"
162 # If we're in no-action mode
163 if Options["No-Action"]:
164 if newpriority != oldpriority:
165 print "I: Would change priority from %s to %s" % (oldpriority,newpriority)
166 if newsection != oldsection:
167 print "I: Would change section from %s to %s" % (oldsection,newsection)
168 if Options.has_key("Done"):
169 print "I: Would also close bug(s): %s" % (Options["Done"])
173 if newpriority != oldpriority:
174 print "I: Will change priority from %s to %s" % (oldpriority,newpriority)
175 if newsection != oldsection:
176 print "I: Will change section from %s to %s" % (oldsection,newsection)
178 if not Options.has_key("Done"):
180 #daklib.utils.warn("No bugs to close have been specified. Noone will know you have done this.")
182 print "I: Will close bug(s): %s" % (Options["Done"])
186 Logger = daklib.logging.Logger(Cnf, "override")
188 projectB.query("BEGIN WORK")
189 # We're in "do it" mode, we have something to do... do it
190 if newpriority != oldpriority:
191 q = projectB.query("""
195 AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
197 pg._quote(package,"str"),
198 pg._quote(suite,"str") ))
199 Logger.log(["changed priority",package,oldpriority,newpriority])
201 if newsection != oldsection:
202 q = projectB.query("""
206 AND suite = (SELECT id FROM suite WHERE suite_name=%s)""" % (
208 pg._quote(package,"str"),
209 pg._quote(suite,"str") ))
210 Logger.log(["changed priority",package,oldsection,newsection])
211 projectB.query("COMMIT WORK")
213 if Options.has_key("Done"):
215 Subst["__OVERRIDE_ADDRESS__"] = Cnf["Override::MyEmailAddress"]
216 Subst["__BUG_SERVER__"] = Cnf["Dinstall::BugServer"]
218 if Cnf.Find("Dinstall::Bcc") != "":
219 bcc.append(Cnf["Dinstall::Bcc"])
220 if Cnf.Find("Override::Bcc") != "":
221 bcc.append(Cnf["Override::Bcc"])
223 Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
225 Subst["__BCC__"] = "X-Filler: 42"
226 Subst["__CC__"] = "X-DAK: dak override\nX-Katie: alicia $Revision: 1.6$"
227 Subst["__ADMIN_ADDRESS__"] = Cnf["Dinstall::MyAdminAddress"]
228 Subst["__DISTRO__"] = Cnf["Dinstall::MyDistribution"]
229 Subst["__WHOAMI__"] = daklib.utils.whoami()
231 summary = "Concerning package %s...\n" % (package)
232 summary += "Operating on the %s suite\n" % (suite)
233 if newpriority != oldpriority:
234 summary += "Changed priority from %s to %s\n" % (oldpriority,newpriority)
235 if newsection != oldsection:
236 summary += "Changed section from %s to %s\n" % (oldsection,newsection)
237 Subst["__SUMMARY__"] = summary
239 for bug in daklib.utils.split_args(Options["Done"]):
240 Subst["__BUG_NUMBER__"] = bug
241 mail_message = daklib.utils.TemplateSubst(
242 Subst,Cnf["Dir::Templates"]+"/override.bug-close")
243 daklib.utils.send_mail(mail_message)
244 Logger.log(["closed bug",bug])
250 #################################################################################
252 if __name__ == '__main__':