]> git.decadent.org.uk Git - dak.git/blob - dak/check_transitions.py
Fix check logic to work the way apt_pkg.VersionCompare wants it. Also parse "not...
[dak.git] / dak / check_transitions.py
1 #!/usr/bin/env python
2
3 # Check the release managers transition file for correctness and outdated transitions
4 # Copyright (C) 2008 Joerg Jaspert <joerg@debian.org>
5
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.
10
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.
15
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
19
20 ################################################################################
21
22 # <elmo> if klecker.d.o died, I swear to god, I'm going to migrate to gentoo.
23
24 ################################################################################
25
26 import os, pg, sys
27 import apt_pkg
28 import daklib.database
29 import daklib.utils
30
31 from syck import *
32
33 # Globals
34 Cnf = None
35 Options = None
36 projectB = None
37
38 ################################################################################
39
40 def init():
41     global Cnf, Options, projectB
42
43     apt_pkg.init()
44
45     Cnf = daklib.utils.get_conf()
46
47     Arguments = [('h',"help","Check-Transitions::Options::Help"),
48                  ('n',"no-action","Check-Transitions::Options::No-Action")]
49
50     for i in ["help", "no-action"]:
51         if not Cnf.has_key("Check-Transitions::Options::%s" % (i)):
52             Cnf["Check-Transitions::Options::%s" % (i)] = ""
53
54     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
55
56     Options = Cnf.SubTree("Check-Transitions::Options")
57
58     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
59     daklib.database.init(Cnf, projectB)
60     
61
62     if Options["help"]:
63         usage()
64
65 ################################################################################
66
67 def usage (exit_code=0):
68     print """Usage: check_transitions [OPTION]...
69   Check the release managers transition file for correctness and outdated transitions
70   -h, --help                show this help and exit.
71   -n, --no-action           don't do anything"""
72     sys.exit(exit_code)
73
74 ################################################################################
75
76 def main():
77     global Cnf
78
79     init()
80     
81     # Only check if there is a file defined (and existant) with checks. It's a little bit
82     # specific to Debian, not much use for others, so return early there.
83     if not Cnf.has_key("Dinstall::Reject::ReleaseTransitions") or not os.path.exists("%s" % (Cnf["Dinstall::Reject::ReleaseTransitions"])):
84         daklib.utils.warn("Dinstall::Reject::ReleaseTransitions not defined or file %s not existant." %
85                           (Cnf["Dinstall::Reject::ReleaseTransitions"]))
86         sys.exit(1)
87     
88     # Parse the yaml file
89     sourcefile = file(Cnf["Dinstall::Reject::ReleaseTransitions"], 'r')
90     sourcecontent = sourcefile.read()
91     try:
92         transitions = load(sourcecontent)
93     except error, msg:
94         # This shouldn't happen, the release team has a wrapper to check the file, but better
95         # safe then sorry
96         daklib.utils.warn("Not checking transitions, the transitions file is broken: %s." % (msg))
97         sys.exit(2)
98
99     to_dump = 0
100     to_remove = []
101     # Now look through all defined transitions
102     for trans in transitions:
103         t = transitions[trans]
104         source = t["source"]
105         new_vers = t["new"]
106
107         # Will be None if nothing is in testing.
108         curvers = daklib.database.get_testing_version(source)
109
110         print """
111 Looking at transition: %s
112  Source:      %s
113  New Version: %s
114  Responsible: %s
115  Description: %s
116  Blocked Packages (total: %d): %s
117 """ % (trans, source, new_vers, t["rm"], t["reason"], len(t["packages"]), ", ".join(t["packages"]))
118
119         if curvers == None:
120             # No package in testing
121             print "Transition source %s not in testing, transition still ongoing." % (source)
122         else:
123             compare = apt_pkg.VersionCompare(curvers, new_vers)
124             print "Apt compare says: %s" % (compare)
125             if compare < 0:
126                 # This is still valid, the current version in database is older than
127                 # the new version we wait for
128                 print "This transition is still ongoing, we currently have version %s" % (curvers)
129             else:
130                 print "This transition is over, the target package reached testing, removing"
131                 print "%s wanted version: %s, has %s" % (source, new_vers, curvers)
132                 to_remove.append(trans)
133                 to_dump = 1
134         print "-------------------------------------------------------------------------"
135
136     if to_dump:
137         for remove in to_remove:
138             if Options["no-action"]:
139                 print "I: I would remove the %s transition" % (remove)
140             else:
141                 del transitions[remove]
142         if not Options["no-action"]:
143             destfile = file(Cnf["Dinstall::Reject::ReleaseTransitions"], 'w')
144             dump(transitions, destfile)
145
146 ################################################################################
147
148 if __name__ == '__main__':
149     main()