~cprov/britney/boottesting-no-skip-notice

« back to all changes in this revision

Viewing changes to britney_util.py

  • Committer: Niels Thykier
  • Date: 2013-11-27 18:46:59 UTC
  • mto: This revision was merged to the branch mainline in revision 419.
  • Revision ID: git-v1:7051d5b0e968936ebbd8a93040e9a2cbe9d3a7e1
Rewrite installability tester

The new Installability Tester (IT) module replaces the remaining
C-parts.  Unlike C-implementation, it does not give up and emit an
"AIEEE" half-way through.

In order to determine installability, it uses two sets "musts" and
"never".  As the names suggest, the sets represents the packages that
must be (co-)installable with the package being tested and those that
can never be co-installable.  For a package to be installable, "musts"
and "never" have remain disjoint.

These sets are also used to reduce the number of alternatives that are
available to satisfy a given dependency.  When these sets are unable
to remove the choice completely, the new IT defers the choice to later.
This occasionally reduces backtracking as a later package may conflict
or unconditionally depend on one of the remaining alternatives.

Signed-off-by: Niels Thykier <niels@thykier.net>

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
    return partial(ifilter, container.__contains__)
83
83
 
84
84
 
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.
 
88
 
 
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.
 
92
 
 
93
    Examples:
 
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)
 
100
 
 
101
    """
 
102
    try:
 
103
        if first is not None:
 
104
            yield first()
 
105
        while 1:
 
106
            yield func()
 
107
    except exception:
 
108
        pass
 
109
 
 
110
 
 
111
def undo_changes(lundo, inst_tester, sources, binaries,
86
112
                 BINARIES=BINARIES, PROVIDES=PROVIDES):
87
113
    """Undoes one or more changes to testing
88
114
 
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
93
119
      and architectures
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)
125
152
 
126
153
 
127
154
    # STEP 3
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)
135
163
            else:
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)
141
171
 
142
172
    # STEP 4
143
173
    # undo all changes to virtual packages