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::Options::Edit"),
49 ('c',"check","Edit-Transitions::Options::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):
86 lock_fd = os.open(lockfile, os.O_RDONLY | os.O_CREAT | os.O_EXCL)
89 if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EEXIST':
92 daklib.utils.fubar("Couldn't obtain lock for %s." % (lockfile) )
94 print("Unable to get lock for %s (try %d of 10)" % (lockfile, retry) )
100 ################################################################################
102 def edit_transitions():
103 trans_file = Cnf["Dinstall::Reject::ReleaseTransitions"]
105 tempfile = "./%s.transition.tmp" % (os.getpid() )
107 lockfile="%s.lock" % (tempfile)
110 daklib.utils.copy(trans_file, tempfile)
112 editor = os.environ.get("EDITOR", "vi")
115 result = os.system("%s %s" % (editor, tempfile))
119 daklib.utils.fubar("%s invocation failed for %s, not removing tempfile." % (editor, tempfile))
121 # Now try to load the new file
122 test = load_transitions(tempfile)
127 prompt = "Broken edit: [E]dit again, Drop changes?"
129 while prompt.find(answer) == -1:
130 answer = daklib.utils.our_raw_input(prompt)
133 answer = answer[:1].upper()
140 print "OK, discarding changes"
143 # No problems in loading the new file, jump out of the while loop
146 # We seem to be done and also have a working file. Copy over.
147 daklib.utils.copy(tempfile, trans_file, True)
151 # Before we finish print out transition info again
152 print "\n\n------------------------------------------------------------------------"
153 print "Edit done, file saved, currently defined transitions:\n"
154 transitions = load_transitions(Cnf["Dinstall::Reject::ReleaseTransitions"])
155 transition_info(transitions)
157 ################################################################################
159 def load_transitions(trans_file):
160 # Parse the yaml file
161 sourcefile = file(trans_file, 'r')
162 sourcecontent = sourcefile.read()
164 trans = syck.load(sourcecontent)
165 except syck.error, msg:
166 # Someone fucked it up
167 print "ERROR: %s" % (msg)
171 ################################################################################
173 def print_info(trans, source, expected, rm, reason, packages):
175 Looking at transition: %s
180 Blocked Packages (total: %d): %s
181 """ % (trans, source, expected, rm, reason, len(packages), ", ".join(packages))
184 ################################################################################
186 def transition_info(transitions):
187 for trans in transitions:
188 t = transitions[trans]
192 # Will be None if nothing is in testing.
193 current = daklib.database.get_suite_version(source, "testing")
195 print_info(trans, source, expected, t["rm"], t["reason"], t["packages"])
198 # No package in testing
199 print "Transition source %s not in testing, transition still ongoing." % (source)
201 compare = apt_pkg.VersionCompare(current, expected)
202 print "Apt compare says: %s" % (compare)
204 # This is still valid, the current version in database is older than
205 # the new version we wait for
206 print "This transition is still ongoing, we currently have version %s" % (current)
208 print "This transition is over, the target package reached testing, should be removed"
209 print "%s wanted version: %s, has %s" % (source, expected, current)
210 print "-------------------------------------------------------------------------"
212 ################################################################################
214 def check_transitions(transitions):
217 # Now look through all defined transitions
218 for trans in transitions:
219 t = transitions[trans]
223 # Will be None if nothing is in testing.
224 current = daklib.database.get_suite_version(source, "testing")
226 print_info(trans, source, expected, t["rm"], t["reason"], t["packages"])
229 # No package in testing
230 print "Transition source %s not in testing, transition still ongoing." % (source)
232 compare = apt_pkg.VersionCompare(current, expected)
233 print "Apt compare says: %s" % (compare)
235 # This is still valid, the current version in database is older than
236 # the new version we wait for
237 print "This transition is still ongoing, we currently have version %s" % (current)
239 print "REMOVE: This transition is over, the target package reached testing. REMOVE"
240 print "%s wanted version: %s, has %s" % (source, expected, current)
241 to_remove.append(trans)
243 print "-------------------------------------------------------------------------"
246 prompt = "Removing: "
247 for remove in to_remove:
251 prompt += " Commit Changes? (y/N)"
254 if Options["no-action"]:
257 answer = daklib.utils.our_raw_input(prompt).lower()
263 print "Not committing changes"
267 for remove in to_remove:
268 del transitions[remove]
269 destfile = file(Cnf["Dinstall::Reject::ReleaseTransitions"], 'w')
270 syck.dump(transitions, destfile)
273 print "WTF are you typing?"
277 ################################################################################
284 # Only check if there is a file defined (and existant) with checks. It's a little bit
285 # specific to Debian, not much use for others, so return early there.
286 if not Cnf.has_key("Dinstall::Reject::ReleaseTransitions") or not os.path.exists("%s" % (Cnf["Dinstall::Reject::ReleaseTransitions"])):
287 daklib.utils.warn("Dinstall::Reject::ReleaseTransitions not defined or file %s not existant." %
288 (Cnf["Dinstall::Reject::ReleaseTransitions"]))
291 # Parse the yaml file
292 transitions = load_transitions(Cnf["Dinstall::Reject::ReleaseTransitions"])
293 if transitions == None:
294 # Something very broken with the transitions, exit
295 daklib.utils.warn("Not doing any work, someone fucked up the transitions file outside our control")
299 # Output information about the currently defined transitions.
300 print "Currently defined transitions:"
301 transition_info(transitions)
302 daklib.utils.our_raw_input("Press enter to continue...")
304 # Lets edit the transitions file
306 elif Options["check"]:
307 # Check and remove outdated transitions
308 check_transitions(transitions)
310 # Output information about the currently defined transitions.
311 transition_info(transitions)
313 # Nothing requested, doing nothing besides the above display of the transitions
317 ################################################################################
319 if __name__ == '__main__':