def load(self, reload=False): """Load the item's properties from its file.""" if self._loaded and not reload: return log.debug("loading {}...".format(repr(self))) # Read text from file text = self._read(self.path) # Parse YAML data from text data = self._load(text, self.path) # Store parsed data for key, value in data.items(): if key == 'level': value = Level(value) elif key == 'active': value = to_bool(value) elif key == 'normative': value = to_bool(value) elif key == 'derived': value = to_bool(value) elif key == 'reviewed': value = Stamp(value) elif key == 'text': value = Text(value) elif key == 'ref': value = value.strip() elif key == 'links': value = set(UID(part) for part in value) elif key == 'header': value = Text(value) else: if isinstance(value, str): value = Text(value) self._data[key] = value # Set meta attributes self._loaded = True
def load(self, reload=False): """Load the item's properties from its file.""" if self._loaded and not reload: return log.debug("loading {}...".format(repr(self))) # Read text from file text = self._read(self.path) # Parse YAML data from text data = self._load(text, self.path) # Store parsed data for key, value in data.items(): if key == 'level': value = Level(value) elif key == 'active': value = to_bool(value) elif key == 'normative': value = to_bool(value) elif key == 'derived': value = to_bool(value) elif key == 'reviewed': value = Stamp(value) elif key == 'text': value = Text(value) elif key == 'ref': value = value.strip() elif key == 'links': value = set(UID(part) for part in value) else: if isinstance(value, str): value = Text(value) self._data[key] = value # Set meta attributes self._loaded = True
def _set_attributes(self, attributes): removed_keys = [] for key, value in attributes.items(): if key == 'deleted': self._data[key] = to_bool(value) elif key == 'pending': self._data[key] = to_bool(value) else: value = None if value is not None: removed_keys.append(key) for key in removed_keys: del attributes[key] super()._set_attributes(attributes)
def heading(self, value): """Set the item's heading status.""" heading = to_bool(value) if heading and not self.heading: self.level.heading = True self.normative = False elif not heading and self.heading: self.level.heading = False self.normative = True
def _set_attributes(self, attributes): """Set the item's attributes.""" self.yaml_validator.validate_item_yaml(attributes) for key, value in attributes.items(): if key == 'level': value = Level(value) elif key == 'active': value = to_bool(value) elif key == 'normative': value = to_bool(value) elif key == 'derived': value = to_bool(value) elif key == 'reviewed': value = Stamp(value) elif key == 'text': value = Text(value) elif key == 'ref': value = value.strip() elif key == 'references': stripped_value = [] for ref_dict in value: ref_type = ref_dict['type'] ref_path = ref_dict['path'] stripped_ref_dict = { "type": ref_type, "path": ref_path.strip() } if 'keyword' in ref_dict: ref_keyword = ref_dict['keyword'] stripped_ref_dict['keyword'] = ref_keyword stripped_value.append(stripped_ref_dict) value = stripped_value elif key == 'links': value = set(UID(part) for part in value) elif key == 'header': value = Text(value) self._data[key] = value
def _set_attributes(self, attributes): """Set the item's attributes.""" for key, value in attributes.items(): if key == 'level': value = Level(value) elif key == 'active': value = to_bool(value) elif key == 'normative': value = to_bool(value) elif key == 'derived': value = to_bool(value) elif key == 'reviewed': value = Stamp(value) elif key == 'text': value = Text(value) elif key == 'ref': value = value.strip() elif key == 'links': value = set(UID(part) for part in value) elif key == 'header': value = Text(value) self._data[key] = value
def cleared(self, value): """Set the item's suspect link status.""" self.clear(_inverse=not to_bool(value))
def normative(self, value): """Set the item's normative status.""" self._data['normative'] = to_bool(value)
def pending(self, value): """Set the item's active status.""" self._data['pending'] = to_bool(value)
def active(self, value): """Set the item's active status.""" self._data['active'] = to_bool(value)
def derived(self, value): """Set the item's derived status.""" self._data['derived'] = to_bool(value)
def deleted(self, value): """Set the item's active status.""" self._data['deleted'] = to_bool(value)