def __validate1 (property): """ Exit with error if property is not valid. """ msg = None f = get_grist (property) if f: value = get_value (property) if not feature.valid (f): f = ungrist (get_grist (property)) # Ungrist for better error messages msg = "Unknown feature '%s'" % f elif value and not 'free' in feature.attributes (f): feature.validate_value_string (f, value) elif not value: f = ungrist (get_grist (property)) # Ungrist for better error messages msg = "No value specified for feature '%s'" % f else: f = feature.implied_feature (property) feature.validate_value_string (f, property) if msg: # FIXME: don't use globals like this. Import here to # break circular dependency. from b2.manager import get_manager get_manager().errors()("Invalid property '%s': %s" % (property, msg))
def translate_paths (properties, path): """ Interpret all path properties in 'properties' as relative to 'path' The property values are assumed to be in system-specific form, and will be translated into normalized form. """ result = [] for p in properties: split = split_conditional (p) condition = '' if split: condition = split [0] p = split [1] if get_grist (p) and 'path' in feature.attributes (get_grist (p)): values = __re_two_ampersands.split (forward_slashes (replace_grist (p, ""))) t = [os.path.join(path, v) for v in values] t = '&&'.join (t) tp = replace_grist (t, get_grist (p)).replace("\\", "/") result.append (condition + tp) else: result.append (condition + p) return result
def take(attributes, properties): """Returns a property set which include all properties in 'properties' that have any of 'attributes'.""" result = [] for e in properties: if b2.util.set.intersection(attributes, feature.attributes(get_grist(e))): result.append(e) return result
def remove(attributes, properties): """Returns a property sets which include all the elements in 'properties' that do not have attributes listed in 'attributes'.""" result = [] for e in properties: attributes_new = feature.attributes(get_grist(e)) has_common_features = 0 for a in attributes_new: if a in attributes: has_common_features = 1 break if not has_common_features: result += e return result
def refine (properties, requirements): """ Refines 'properties' by overriding any non-free properties for which a different value is specified in 'requirements'. Conditional requirements are just added without modification. Returns the resulting list of properties. """ # The result has no duplicates, so we store it in a map # TODO: use a set from Python 2.4? result = {} # Records all requirements. required = {} # All the elements of requirements should be present in the result # Record them so that we can handle 'properties'. for r in requirements: # Don't consider conditional requirements. if not is_conditional (r): # Note: cannot use local here, so take an ugly name required [get_grist (r)] = replace_grist (r, '') for p in properties: # Skip conditional properties if is_conditional (p): result [p] = None # No processing for free properties elif 'free' in feature.attributes (get_grist (p)): result [p] = None else: if required.has_key (get_grist (p)): required_value = required [get_grist (p)] value = replace_grist (p, '') if value != required_value: result [replace_grist (required_value, get_grist (p))] = None else: result [p] = None else: result [p] = None return result.keys () + requirements
def remove(attributes, properties): """Returns a property sets which include all the elements in 'properties' that do not have attributes listed in 'attributes'.""" if isinstance(attributes, basestring): attributes = [attributes] assert is_iterable_typed(attributes, basestring) assert is_iterable_typed(properties, basestring) result = [] for e in properties: attributes_new = feature.attributes(get_grist(e)) has_common_features = 0 for a in attributes_new: if a in attributes: has_common_features = 1 break if not has_common_features: result += e return result
def __init__(self, properties=[]): raw_properties = [] for p in properties: raw_properties.append(p.to_raw()) self.all_ = properties self.all_raw_ = raw_properties self.all_set_ = set(properties) self.incidental_ = [] self.free_ = [] self.base_ = [] self.dependency_ = [] self.non_dependency_ = [] self.conditional_ = [] self.non_conditional_ = [] self.propagated_ = [] self.link_incompatible = [] # A cache of refined properties. self.refined_ = {} # A cache of property sets created by adding properties to this one. self.added_ = {} # Cache for the default properties. self.defaults_ = None # Cache for the expanded properties. self.expanded_ = None # Cache for the expanded composite properties self.composites_ = None # Cache for property set with expanded subfeatures self.subfeatures_ = None # Cache for the property set containing propagated properties. self.propagated_ps_ = None # A map of features to its values. self.feature_map_ = None # A tuple (target path, is relative to build directory) self.target_path_ = None self.as_path_ = None # A cache for already evaluated sets. self.evaluated_ = {} for p in raw_properties: if not get_grist(p): raise BaseException("Invalid property: '%s'" % p) att = feature.attributes(get_grist(p)) if 'propagated' in att: self.propagated_.append(p) if 'link_incompatible' in att: self.link_incompatible.append(p) for p in properties: # A feature can be both incidental and free, # in which case we add it to incidental. if p.feature().incidental(): self.incidental_.append(p) elif p.feature().free(): self.free_.append(p) else: self.base_.append(p) if p.condition(): self.conditional_.append(p) else: self.non_conditional_.append(p) if p.feature().dependency(): self.dependency_.append(p) else: self.non_dependency_.append(p)