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