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 -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 Arguments = [('h',"help","Override::Options::Help"),
62 ('d',"done","Override::Options::Done", "HasArg"),
63 ('n',"no-action","Override::Options::No-Action"),
64 ('s',"suite","Override::Options::Suite", "HasArg"),
66 for i in ["help", "no-action"]:
67 if not cnf.has_key("Override::Options::%s" % (i)):
68 cnf["Override::Options::%s" % (i)] = ""
69 if not cnf.has_key("Override::Options::Suite"):
70 cnf["Override::Options::Suite"] = "unstable"
72 arguments = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
73 Options = cnf.SubTree("Override::Options")
78 session = DBConn().session()
81 utils.fubar("package name is a required argument.")
83 package = arguments.pop(0)
84 suite = Options["Suite"]
85 if arguments and len(arguments) > 2:
86 utils.fubar("Too many arguments")
88 if arguments and len(arguments) == 1:
89 # Determine if the argument is a priority or a section...
91 q = session.execute("""
92 SELECT ( SELECT COUNT(*) FROM section WHERE section = :arg ) AS secs,
93 ( SELECT COUNT(*) FROM priority WHERE priority = :arg ) AS prios
97 arguments = (arg, ".")
99 arguments = (".", arg)
101 utils.fubar("%s is not a valid section or priority" % (arg))
103 # Retrieve current section/priority...
104 oldsection, oldsourcesection, oldpriority = None, None, None
105 for packagetype in ['source', 'binary']:
107 if packagetype == 'source':
109 q = session.execute("""
110 SELECT priority.priority AS prio, section.section AS sect, override_type.type AS type
111 FROM override, priority, section, suite, override_type
112 WHERE override.priority = priority.id
113 AND override.type = override_type.id
114 AND override_type.type %s 'dsc'
115 AND override.section = section.id
116 AND override.package = :package
117 AND override.suite = suite.id
118 AND suite.suite_name = :suite
119 """ % (eqdsc), {'package': package, 'suite': suite})
124 utils.fubar("%s is ambiguous. Matches %d packages" % (package,q.ntuples()))
127 if packagetype == 'binary':
131 oldsourcesection = r[1]
132 oldpriority = 'source'
134 if not oldpriority and not oldsourcesection:
135 utils.fubar("Unable to find package %s" % (package))
137 if oldsection and oldsourcesection and oldsection != oldsourcesection:
138 # When setting overrides, both source & binary will become the same section
139 utils.warn("Source is in section '%s' instead of '%s'" % (oldsourcesection, oldsection))
142 oldsection = oldsourcesection
145 print "%s is in section '%s' at priority '%s'" % (
146 package, oldsection, oldpriority)
149 # At this point, we have a new section and priority... check they're valid...
150 newsection, newpriority = arguments
152 if newsection == ".":
153 newsection = oldsection
154 if newpriority == ".":
155 newpriority = oldpriority
157 s = get_section(newsection, session)
159 utils.fubar("Supplied section %s is invalid" % (newsection))
160 newsecid = s.section_id
162 p = get_priority(newpriority, session)
164 utils.fubar("Supplied priority %s is invalid" % (newpriority))
165 newprioid = p.priority_id
167 if newpriority == oldpriority and newsection == oldsection:
168 print "I: Doing nothing"
171 if oldpriority == 'source' and newpriority != 'source':
172 utils.fubar("Trying to change priority of a source-only package")
174 # If we're in no-action mode
175 if Options["No-Action"]:
176 if newpriority != oldpriority:
177 print "I: Would change priority from %s to %s" % (oldpriority,newpriority)
178 if newsection != oldsection:
179 print "I: Would change section from %s to %s" % (oldsection,newsection)
180 if Options.has_key("Done"):
181 print "I: Would also close bug(s): %s" % (Options["Done"])
185 if newpriority != oldpriority:
186 print "I: Will change priority from %s to %s" % (oldpriority,newpriority)
188 if newsection != oldsection:
189 print "I: Will change section from %s to %s" % (oldsection,newsection)
191 if not Options.has_key("Done"):
193 #utils.warn("No bugs to close have been specified. Noone will know you have done this.")
195 print "I: Will close bug(s): %s" % (Options["Done"])
199 Logger = daklog.Logger(cnf.Cnf, "override")
201 dsc_otype_id = get_override_type('dsc').overridetype_id
203 # We're already in a transaction
204 # We're in "do it" mode, we have something to do... do it
205 if newpriority != oldpriority:
208 SET priority = :newprioid
209 WHERE package = :package
210 AND override.type != :otypedsc
211 AND suite = (SELECT id FROM suite WHERE suite_name = :suite)""",
212 {'newprioid': newprioid, 'package': package,
213 'otypedsc': dsc_otype_id, 'suite': suite})
215 Logger.log(["changed priority", package, oldpriority, newpriority])
217 if newsection != oldsection:
218 q = session.execute("""
220 SET section = :newsecid
221 WHERE package = :package
222 AND suite = (SELECT id FROM suite WHERE suite_name = :suite)""",
223 {'newsecid': newsecid, 'package': package,
226 Logger.log(["changed section", package, oldsection, newsection])
230 if Options.has_key("Done"):
232 Subst["__OVERRIDE_ADDRESS__"] = cnf["Override::MyEmailAddress"]
233 Subst["__BUG_SERVER__"] = cnf["Dinstall::BugServer"]
235 if cnf.Find("Dinstall::Bcc") != "":
236 bcc.append(cnf["Dinstall::Bcc"])
237 if cnf.Find("Override::Bcc") != "":
238 bcc.append(cnf["Override::Bcc"])
240 Subst["__BCC__"] = "Bcc: " + ", ".join(bcc)
242 Subst["__BCC__"] = "X-Filler: 42"
243 Subst["__CC__"] = "Cc: " + package + "@" + Cnf["Dinstall::PackagesServer"] + "\nX-DAK: dak override"
244 Subst["__ADMIN_ADDRESS__"] = Cnf["Dinstall::MyAdminAddress"]
245 Subst["__DISTRO__"] = Cnf["Dinstall::MyDistribution"]
246 Subst["__WHOAMI__"] = utils.whoami()
247 Subst["__SOURCE__"] = package
249 summary = "Concerning package %s...\n" % (package)
250 summary += "Operating on the %s suite\n" % (suite)
251 if newpriority != oldpriority:
252 summary += "Changed priority from %s to %s\n" % (oldpriority,newpriority)
253 if newsection != oldsection:
254 summary += "Changed section from %s to %s\n" % (oldsection,newsection)
255 Subst["__SUMMARY__"] = summary
257 template = os.path.join(cnf["Dir::Templates"], "override.bug-close")
258 for bug in utils.split_args(Options["Done"]):
259 Subst["__BUG_NUMBER__"] = bug
260 mail_message = utils.TemplateSubst(Subst, template)
261 utils.send_mail(mail_message)
262 Logger.log(["closed bug", bug])
266 #################################################################################
268 if __name__ == '__main__':