]> git.decadent.org.uk Git - dak.git/blob - config/debian/extensions.py
move process_unchecked changes intoconfig/debian/extensions.py
[dak.git] / config / debian / extensions.py
1 import sys, os, textwrap
2
3 import apt_pkg
4 import daklib.utils, daklib.database
5 import syck
6
7 # This function and its data should move into daklib/extensions.py
8 # or something.
9 replaced_funcs = {}
10 replace_funcs = {}
11 def replace_dak_function(module,name):
12     def x(f):
13         replace_funcs["%s:%s" % (module,name)] = f
14     return x
15
16 def check_transition():
17     changes = dak_module.changes
18     reject = dak_module.reject
19     Cnf = dak_module.Cnf
20
21     sourcepkg = changes["source"]
22
23     # No sourceful upload -> no need to do anything else, direct return
24     if "source" not in changes["architecture"]:
25         return
26
27     # Also only check if there is a file defined (and existant) with 
28     # checks.
29     transpath = Cnf.get("Dinstall::Reject::ReleaseTransitions", "")
30     if transpath == "" or not os.path.exists(transpath):
31         return
32     
33     # Parse the yaml file
34     sourcefile = file(transpath, 'r')
35     sourcecontent = sourcefile.read()
36     try:
37         transitions = syck.load(sourcecontent)
38     except syck.error, msg:
39         # This shouldn't happen, there is a wrapper to edit the file which
40         # checks it, but we prefer to be safe than ending up rejecting
41         # everything.
42         daklib.utils.warn("Not checking transitions, the transitions file is broken: %s." % (msg))
43         return
44
45     # Now look through all defined transitions
46     for trans in transitions:
47         t = transitions[trans]
48         source = t["source"]
49         expected = t["new"]
50
51         # Will be None if nothing is in testing.
52         current = daklib.database.get_suite_version(source, "testing")
53         if current is not None:
54             compare = apt_pkg.VersionCompare(current, expected)
55
56         if current is None or compare < 0:
57             # This is still valid, the current version in testing is older than
58             # the new version we wait for, or there is none in testing yet
59
60             # Check if the source we look at is affected by this.
61             if sourcepkg in t['packages']:
62                 # The source is affected, lets reject it.
63
64                 rejectmsg = "%s: part of the %s transition.\n\n" % (
65                         sourcepkg, trans)
66
67                 if current is not None:
68                     currentlymsg = "at version %s" % (current)
69                 else:
70                     currentlymsg = "not present in testing"
71
72                 rejectmsg += "Transition description: %s\n\n" % (t["reason"])
73
74                 rejectmsg += "\n".join(textwrap.wrap("""Your package
75 is part of a testing transition designed to get %s migrated (it is
76 currently %s, we need version %s).  This transition is managed by the
77 Release Team, and %s is the Release-Team member responsible for it.
78 Please mail debian-release@lists.debian.org or contact %s directly if you
79 need further assistance."""
80                         % (source, currentlymsg, expected,t["rm"], t["rm"])))
81
82                 reject(rejectmsg + "\n")
83                 return
84
85 @replace_dak_function("process-unchecked", "check_signed_by_key")
86 def check_signed_by_key():
87     changes = dak_module.changes
88     reject = dak_module.reject
89
90     if changes["source"] == "dpkg":
91         fpr = changes["fingerprint"]
92         (uid, uid_name) = dak_module.lookup_uid_from_fingerprint(fpr)
93         if fpr == "5906F687BD03ACAD0D8E602EFCF37657" or uid == "iwj":
94             reject("Upload blocked due to hijack attempt 2008/03/19")
95
96             # NB: 1.15.0, 1.15.2 signed by this key targetted at unstable
97             #     have been made available in the wild, and should not be
98             #     blocked until Debian's dpkg has revved past those version
99             #     numbers
100
101     replaced_funcs["check_signed_by_key"]()
102
103     check_transition()
104
105 def init(name):
106     global replaced_funcs
107
108     # This bit should be done automatically too
109     replaced_funcs = {}
110     for f,newfunc in replace_funcs.iteritems():
111         m,f = f.split(":",1)
112         if len(f) > 0 and m == name:
113             replaced_funcs[f] = dak_module.__dict__[f]
114             dak_module.__dict__[f] = newfunc
115