def set_condition(self, expr): # 'foo | bar & baz' # 'foo:fail | foo' # 'foo[T-6]:out1 | baz' drop_these = [] if hasattr(self, 'all_satisfied'): delattr(self, 'all_satisfied') if self.pre_initial_messages: for k in self.pre_initial_messages: drop_these.append(k) # Needed to drop pre warm-start dependence: for k in self.messages: if k in drop_these: continue if self.start_point: m = re.search( r'(' + TaskID.NAME_RE + ')\.(' + TaskID.POINT_RE + ') ', self.messages[k]) if m: try: foo = m.group().split(".")[1].rstrip() if (get_point(foo) < self.start_point and self.point >= self.start_point): drop_these.append(k) except IndexError: pass for label in drop_these: if self.messages.get(label): msg = self.messages[label] self.messages.pop(label) self.messages_set.remove(msg) self.satisfied.pop(label) self.labels.pop(msg) if '|' in expr: if drop_these: simpler = ConditionalSimplifier(expr, drop_these) expr = simpler.get_cleaned() # Make a Python expression so we can eval() the logic. self.raw_conditional_expression = expr for label in self.messages: expr = re.sub( r'\b' + label + r'\b', 'self.satisfied[\'' + label + '\']', expr) self.conditional_expression = expr
def set_condition(self, expr): # 'foo | bar & baz' # 'foo:fail | foo' # 'foo[T-6]:out1 | baz' drop_these = [] if hasattr(self, 'all_satisfied'): delattr(self, 'all_satisfied') if self.pre_initial_messages: for message in self.pre_initial_messages: drop_these.append(message) # Needed to drop pre warm-start dependence: for message in self.messages: if message in drop_these: continue if self.start_point: # Extract the cycle point from the message. match = self.CYCLE_POINT_RE.search(message) if match: # Get cycle point if (get_point(match.groups()[0]) < self.start_point and self.point >= self.start_point): # Drop if outside of relevant point range. drop_these.append(message) for message in drop_these: if message in self.messages: self.messages.remove(message) self.satisfied.pop(message) if '|' in expr: if drop_these: simpler = ConditionalSimplifier(expr, drop_these) expr = simpler.get_cleaned() # Make a Python expression so we can eval() the logic. for message in self.messages: expr = expr.replace(message, self.SATISFIED_TEMPLATE % message) self.conditional_expression = expr
def set_condition(self, expr): """Set the conditional expression for this prerequisite. Resets the cached state (self._all_satisfied). """ drop_these = [] self._all_satisfied = None if self.pre_initial_messages: for message in self.pre_initial_messages: drop_these.append(message) # Needed to drop pre warm-start dependence: for message in self.satisfied: if message in drop_these: continue if self.start_point: if message[1]: # Cycle point. if (get_point(message[1]) < self.start_point and self.point >= self.start_point): # Drop if outside of relevant point range. drop_these.append(message) for message in drop_these: if message in self.satisfied: self.satisfied.pop(message) if '|' in expr: if drop_these: simpler = ConditionalSimplifier( expr, [self.MESSAGE_TEMPLATE % m for m in drop_these]) expr = simpler.get_cleaned() # Make a Python expression so we can eval() the logic. for message in self.satisfied: expr = expr.replace(self.MESSAGE_TEMPLATE % message, self.SATISFIED_TEMPLATE % message) self.conditional_expression = expr