82
82
return partial(ifilter, container.__contains__)
85
def undo_changes(lundo, systems, sources, binaries,
85
# iter_except is from the "itertools" recipe
86
def iter_except(func, exception, first=None):
87
""" Call a function repeatedly until an exception is raised.
89
Converts a call-until-exception interface to an iterator interface.
90
Like __builtin__.iter(func, sentinel) but uses an exception instead
91
of a sentinel to end the loop.
94
bsddbiter = iter_except(db.next, bsddb.error, db.first)
95
heapiter = iter_except(functools.partial(heappop, h), IndexError)
96
dictiter = iter_except(d.popitem, KeyError)
97
dequeiter = iter_except(d.popleft, IndexError)
98
queueiter = iter_except(q.get_nowait, Queue.Empty)
99
setiter = iter_except(s.pop, KeyError)
103
if first is not None:
111
def undo_changes(lundo, inst_tester, sources, binaries,
86
112
BINARIES=BINARIES, PROVIDES=PROVIDES):
87
113
"""Undoes one or more changes to testing
89
115
* lundo is a list of (undo, item)-tuples
90
* systems is the britney-py.c system
116
* inst_tester is an InstallabilityTester
91
117
* sources is the table of all source packages for all suites
92
118
* binaries is the table of all binary packages for all suites
120
146
for p in sources[item.suite][item.package][BINARIES]:
121
147
binary, arch = p.split("/")
122
148
if item.architecture in ['source', arch]:
149
version = binaries["testing"][arch][0][binary][VERSION]
123
150
del binaries["testing"][arch][0][binary]
124
systems[arch].remove_binary(binary)
151
inst_tester.remove_testing_binary(binary, version, arch)
130
157
for p in undo['binaries']:
131
158
binary, arch = p.split("/")
132
159
if binary[0] == "-":
160
version = binaries["testing"][arch][0][binary][VERSION]
133
161
del binaries['testing'][arch][0][binary[1:]]
134
systems[arch].remove_binary(binary[1:])
162
inst_tester.remove_testing_binary(binary, version, arch)
136
164
binaries_t_a = binaries['testing'][arch][0]
137
binaries_t_a[binary] = undo['binaries'][p]
138
systems[arch].remove_binary(binary)
139
systems[arch].add_binary(binary, binaries_t_a[binary][:PROVIDES] + \
140
[", ".join(binaries_t_a[binary][PROVIDES]) or None])
165
if p in binaries_t_a:
166
rmpkgdata = binaries_t_a[p]
167
inst_tester.remove_testing_binary(binary, rmpkgdata[VERSION], arch)
168
pkgdata = undo['binaries'][p]
169
binaries_t_a[binary] = pkgdata
170
inst_tester.add_testing_binary(binary, pkgdata[VERSION], arch)
143
173
# undo all changes to virtual packages