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 ################################################################################
32 from daklib.config import Config
33 from daklib.dbconn import *
34 from daklib import daklog
35 from daklib import utils
37 ################################################################################
39 # Shamelessly stolen from 'dak rm'. Should probably end up in utils.py
41 answer = 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 binary overrides
51 -h, --help show this help and exit
52 -c, --check check override compliance
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
59 def check_override_compliance(package, priority, suite, cnf, session):
60 print "Checking compliance with related overrides..."
64 components = get_component_names(session)
65 arches = set([x.arch_string for x in get_suite_architectures(suite)])
66 arches -= set(["source", "all"])
68 for component in components:
69 Packages = utils.get_packages_from_ftp(cnf['Dir::Root'], suite, component, arch)
70 while Packages.Step():
71 package_name = Packages.Section.Find("Package")
72 dep_list = Packages.Section.Find("Depends")
74 if package_name == package:
75 for d in apt_pkg.ParseDepends(dep_list):
79 for d in apt_pkg.ParseDepends(dep_list):
82 rdepends.add(package_name)
84 query = """SELECT o.package, p.level, p.priority
86 JOIN suite s ON s.id = o.suite
87 JOIN priority p ON p.id = o.priority
88 WHERE s.suite_name = '%s'
89 AND o.package in ('%s')""" \
90 % (suite, "', '".join(depends.union(rdepends)))
91 packages = session.execute(query)
95 if p[0] == package or not p[1]:
98 if priority.level < p[1]:
99 excuses.append("%s would have priority %s, its dependency %s has priority %s" \
100 % (package, priority.priority, p[0], p[2]))
102 if priority.level > p[1]:
103 excuses.append("%s would have priority %s, its reverse dependency %s has priority %s" \
104 % (package, priority.priority, p[0], p[2]))
110 print "Proposed override change complies with Debian Policy"
115 Arguments = [('h',"help","Override::Options::Help"),
116 ('c',"check","Override::Options::Check"),
117 ('d',"done","Override::Options::Done", "HasArg"),
118 ('n',"no-action","Override::Options::No-Action"),
119 ('s',"suite","Override::Options::Suite", "HasArg"),
121 for i in ["help", "check", "no-action"]:
122 if not cnf.has_key("Override::Options::%s" % (i)):
123 cnf["Override::Options::%s" % (i)] = ""
124 if not cnf.has_key("Override::Options::Suite"):
125 cnf["Override::Options::Suite"] = "unstable"
127 arguments = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
128 Options = cnf.SubTree("Override::Options")
133 session = DBConn().session()
136 utils.fubar("package name is a required argument.")
138 package = arguments.pop(0)
139 suite = Options["Suite"]
140 if arguments and len(arguments) > 2:
141 utils.fubar("Too many arguments")
143 if arguments and len(arguments) == 1:
144 # Determine if the argument is a priority or a section...
145 arg = arguments.pop()
146 q = session.execute("""
147 SELECT ( SELECT COUNT(*) FROM section WHERE section = :arg ) AS secs,
148 ( SELECT COUNT(*) FROM priority WHERE priority = :arg ) AS prios
152 arguments = (arg, ".")
154 arguments = (".", arg)
156 utils.fubar("%s is not a valid section or priority" % (arg))
158 # Retrieve current section/priority...
159 oldsection, oldsourcesection, oldpriority = None, None, None
160 for packagetype in ['source', 'binary']:
162 if packagetype == 'source':
164 q = session.execute("""
165 SELECT priority.priority AS prio, section.section AS sect, override_type.type AS type
166 FROM override, priority, section, suite, override_type
167 WHERE override.priority = priority.id
168 AND override.type = override_type.id
169 AND override_type.type %s 'dsc'
170 AND override.section = section.id
171 AND override.package = :package
172 AND override.suite = suite.id
173 AND suite.suite_name = :suite
174 """ % (eqdsc), {'package': package, 'suite': suite})
179 utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.rowcount))
182 if packagetype == 'binary':
186 oldsourcesection = r[1]
187 oldpriority = 'source'
189 if not oldpriority and not oldsourcesection:
190 utils.fubar("Unable to find package %s" % (package))
192 if oldsection and oldsourcesection and oldsection != oldsourcesection:
193 # When setting overrides, both source & binary will become the same section
194 utils.warn("Source is in section '%s' instead of '%s'" % (oldsourcesection, oldsection))
197 oldsection = oldsourcesection
200 print "%s is in section '%s' at priority '%s'" % (
201 package, oldsection, oldpriority)
204 # At this point, we have a new section and priority... check they're valid...
205 newsection, newpriority = arguments
207 if newsection == ".":
208 newsection = oldsection
209 if newpriority == ".":
210 newpriority = oldpriority
212 s = get_section(newsection, session)
214 utils.fubar("Supplied section %s is invalid" % (newsection))
215 newsecid = s.section_id
217 p = get_priority(newpriority, session)
219 utils.fubar("Supplied priority %s is invalid" % (newpriority))
220 newprioid = p.priority_id
222 if newpriority == oldpriority and newsection == oldsection:
223 print "I: Doing nothing"
226 if oldpriority == 'source' and newpriority != 'source':
227 utils.fubar("Trying to change priority of a source-only package")
229 if Options["Check"] and newpriority != oldpriority:
230 check_override_compliance(package, p, suite, cnf, session)
232 # If we're in no-action mode
233 if Options["No-Action"]:
234 if newpriority != oldpriority:
235 print "I: Would change priority from %s to %s" % (oldpriority,newpriority)
236 if newsection != oldsection:
237 print "I: Would change section from %s to %s" % (oldsection,newsection)
238 if Options.has_key("Done"):
239 print "I: Would also close bug(s): %s" % (Options["Done"])
243 if newpriority != oldpriority:
244 print "I: Will change priority from %s to %s" % (oldpriority,newpriority)
246 if newsection != oldsection:
247 print "I: Will change section from %s to %s" % (oldsection,newsection)
249 if not Options.has_key("Done"):
251 #utils.warn("No bugs to close have been specified. Noone will know you have done this.")
253 print "I: Will close bug(s): %s" % (Options["Done"])
257 Logger = daklog.Logger("override")
259 dsc_otype_id = get_override_type('dsc').overridetype_id
261 # We're already in a transaction
262 # We're in "do it" mode, we have something to do... do it
263 if newpriority != oldpriority:
266 SET priority = :newprioid
267 WHERE package = :package
268 AND override.type != :otypedsc
269 AND suite = (SELECT id FROM suite WHERE suite_name = :suite)""",
270 {'newprioid': newprioid, 'package': package,
271 'otypedsc': dsc_otype_id, 'suite': suite})
273 Logger.log(["changed priority", package, oldpriority, newpriority])
275 if newsection != oldsection:
276 q = session.execute("""
278 SET section = :newsecid
279 WHERE package = :package
280 AND suite = (SELECT id FROM suite WHERE suite_name = :suite)""",
281 {'newsecid': newsecid, 'package': package,
284 Logger.log(["changed section", package, oldsection, newsection])
288 if Options.has_key("Done"):
289 if not cnf.has_key("Dinstall::BugServer"):
290 utils.warn("Asked to send Done message but Dinstall::BugServer is not configured")
295 Subst["__OVERRIDE_ADDRESS__"] = cnf["Dinstall::MyEmailAddress"]
296 Subst["__BUG_SERVER__"] = cnf["Dinstall::BugServer"]
298 if cnf.Find("Dinstall::Bcc") != "":
299 bcc.append(cnf["Dinstall::Bcc"])
301 Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
303 Subst["__BCC__"] = "X-Filler: 42"
304 if cnf.has_key("Dinstall::PackagesServer"):
305 Subst["__CC__"] = "Cc: " + package + "@" + cnf["Dinstall::PackagesServer"] + "\nX-DAK: dak override"
307 Subst["__CC__"] = "X-DAK: dak override"
308 Subst["__ADMIN_ADDRESS__"] = cnf["Dinstall::MyAdminAddress"]
309 Subst["__DISTRO__"] = cnf["Dinstall::MyDistribution"]
310 Subst["__WHOAMI__"] = utils.whoami()
311 Subst["__SOURCE__"] = package
313 summary = "Concerning package %s...\n" % (package)
314 summary += "Operating on the %s suite\n" % (suite)
315 if newpriority != oldpriority:
316 summary += "Changed priority from %s to %s\n" % (oldpriority,newpriority)
317 if newsection != oldsection:
318 summary += "Changed section from %s to %s\n" % (oldsection,newsection)
319 Subst["__SUMMARY__"] = summary
321 template = os.path.join(cnf["Dir::Templates"], "override.bug-close")
322 for bug in utils.split_args(Options["Done"]):
323 Subst["__BUG_NUMBER__"] = bug
324 mail_message = utils.TemplateSubst(Subst, template)
325 utils.send_mail(mail_message)
326 Logger.log(["closed bug", bug])
330 #################################################################################
332 if __name__ == '__main__':