3 # Edit and then check the release managers transition file for correctness
4 # and outdated transitions
5 # Copyright (C) 2008 Joerg Jaspert <joerg@debian.org>
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
21 ################################################################################
23 # <elmo> if klecker.d.o died, I swear to god, I'm going to migrate to gentoo.
25 ################################################################################
27 import os, pg, sys, time
29 import daklib.database
38 ################################################################################
41 global Cnf, Options, projectB
45 Cnf = daklib.utils.get_conf()
47 Arguments = [('h',"help","Edit-Transitions::Options::Help"),
48 ('e',"edit","Edit-Transitions::Option::Edit"),
49 ('c',"check","Edit-Transitions::Option::check"),
50 ('n',"no-action","Edit-Transitions::Options::No-Action")]
52 for i in ["help", "no-action", "edit", "check"]:
53 if not Cnf.has_key("Edit-Transitions::Options::%s" % (i)):
54 Cnf["Edit-Transitions::Options::%s" % (i)] = ""
56 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
58 Options = Cnf.SubTree("Edit-Transitions::Options")
60 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
61 daklib.database.init(Cnf, projectB)
66 ################################################################################
68 def usage (exit_code=0):
69 print """Usage: edit_transitions [OPTION]...
70 Check the release managers transition file for correctness and outdated transitions
71 -h, --help show this help and exit.
72 -e, --edit edit the transitions file
73 -c, --check check the transitions file, remove outdated entries
74 -n, --no-action don't do anything
76 Called without an option this tool will check the transition file for outdated
77 transitions and remove them."""
80 ################################################################################
82 def lock_file(lockfile):
85 lock_fd = os.open(lockfile, os.O_RDONLY | os.O_CREAT | os.O_EXCL)
88 if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EEXIST':
91 daklib.utils.fubar("Couldn't obtain lock for %s." % (lockfile) )
93 print("Unable to get lock for %s (try %d of 10)" % (lockfile, retry) )
99 ################################################################################
101 def edit_transitions():
102 trans_file = Cnf["Dinstall::Reject::ReleaseTransitions"]
104 tempfile = "./%s.transition.tmp" % (os.getpid() )
106 lockfile="%s.lock" % (tempfile)
109 daklib.utils.copy(trans_file, tempfile )
111 editor = os.environ.get("EDITOR", "vi")
114 result = os.system("%s %s" % (editor, temp_file))
118 daklib.utils.fubar("%s invocation failed for %s, not removing tempfile." % (editor, temp_file))
120 # Now try to load the new file
121 test = load_transitions(tempfile)
125 prompt = "Broken edit: [E]dit again, Drop changes?"
126 while prompt.find(answer) == -1:
127 answer = daklib.utils.our_raw_input(prompt)
128 m = daklib.queue.re_default_answer.match(prompt)
131 answer = answer[:1].upper()
140 # No problems in loading the new file, jump out of the while loop
143 # We seem to be done and also have a working file. Copy over.
144 daklib.utils.copy(tempfile, trans_file)
148 ################################################################################
150 def load_transitions(trans_file):
151 # Parse the yaml file
152 sourcefile = file(trans_file, 'r')
153 sourcecontent = sourcefile.read()
155 trans = syck.load(sourcecontent)
157 # Someone fucked it up
158 print "ERROR: %s" % (msg)
162 ################################################################################
164 def print_info(trans, source, expected, rm, reason, packages):
166 Looking at transition: %s
171 Blocked Packages (total: %d): %s
172 """ % (trans, source, expected, rm, reason, len(packages), ", ".join(packages))
175 ################################################################################
177 def transition_info(transitions):
178 print "Currently defined transitions:"
179 for trans in transitions:
180 t = transitions[trans]
184 # Will be None if nothing is in testing.
185 current = daklib.database.get_testing_version(source)
187 print_info(trans, source, expected, t["rm"], t["reason"], t["packages"])
190 # No package in testing
191 print "Transition source %s not in testing, transition still ongoing." % (source)
193 compare = apt_pkg.VersionCompare(current, expected)
194 print "Apt compare says: %s" % (compare)
196 # This is still valid, the current version in database is older than
197 # the new version we wait for
198 print "This transition is still ongoing, we currently have version %s" % (current)
200 print "This transition is over, the target package reached testing, should be removed"
201 print "%s wanted version: %s, has %s" % (source, expected, current)
202 print "-------------------------------------------------------------------------"
204 ################################################################################
206 def check_transitions(transitions):
209 # Now look through all defined transitions
210 for trans in transitions:
211 t = transitions[trans]
215 # Will be None if nothing is in testing.
216 current = daklib.database.get_testing_version(source)
218 print_info(trans, source, expected, t["rm"], t["reason"], t["packages"])
221 # No package in testing
222 print "Transition source %s not in testing, transition still ongoing." % (source)
224 compare = apt_pkg.VersionCompare(current, expected)
225 print "Apt compare says: %s" % (compare)
227 # This is still valid, the current version in database is older than
228 # the new version we wait for
229 print "This transition is still ongoing, we currently have version %s" % (current)
231 print "REMOVE: This transition is over, the target package reached testing. REMOVE"
232 print "%s wanted version: %s, has %s" % (source, expected, current)
233 to_remove.append(trans)
235 print "-------------------------------------------------------------------------"
238 prompt = "Removing: "
239 for remove in to_remove:
243 prompt += " Commit Changes? (y/N)"
245 if Options["no-action"]:
248 answer = daklib.utils.our_raw_input(prompt).lower()
254 print "Not committing changes"
258 for remove in to_remove:
259 del transitions[remove]
260 destfile = file(Cnf["Dinstall::Reject::ReleaseTransitions"], 'w')
261 syck.dump(transitions, destfile)
264 print "WTF are you typing?"
268 ################################################################################
275 # Only check if there is a file defined (and existant) with checks. It's a little bit
276 # specific to Debian, not much use for others, so return early there.
277 if not Cnf.has_key("Dinstall::Reject::ReleaseTransitions") or not os.path.exists("%s" % (Cnf["Dinstall::Reject::ReleaseTransitions"])):
278 daklib.utils.warn("Dinstall::Reject::ReleaseTransitions not defined or file %s not existant." %
279 (Cnf["Dinstall::Reject::ReleaseTransitions"]))
282 # Parse the yaml file
283 transitions = load_transitions(Cnf["Dinstall::Reject::ReleaseTransitions"])
284 if transitions = None:
285 # Something very broken with the transitions, exit
286 daklib.utils.warn("Not doing any work, someone fucked up the transitions file outside our control")
290 # Output information about the currently defined transitions.
291 transition_info(transitions)
292 daklib.utils.our_raw_input("Press a key to continue...")
294 # Lets edit the transitions file
295 edit_transitions(Cnf["Dinstall::Reject::ReleaseTransitions"])
296 elif Options["check"]:
297 # Check and remove outdated transitions
298 check_transitions(transitions, Cnf["Dinstall::Reject::ReleaseTransitions"])
300 # Output information about the currently defined transitions.
301 transition_info(transitions)
302 daklib.utils.our_raw_input("Press a key to continue...")
304 # Nothing requested, doing nothing besides the above display of the transitions
308 ################################################################################
310 if __name__ == '__main__':