Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 def cleared(self, value):
     """Set the item's suspect link status."""
     self.clear(_inverse=not to_bool(value))
Ejemplo n.º 9
0
 def normative(self, value):
     """Set the item's normative status."""
     self._data['normative'] = to_bool(value)
Ejemplo n.º 10
0
 def pending(self, value):
     """Set the item's active status."""
     self._data['pending'] = to_bool(value)
Ejemplo n.º 11
0
 def active(self, value):
     """Set the item's active status."""
     self._data['active'] = to_bool(value)
Ejemplo n.º 12
0
 def derived(self, value):
     """Set the item's derived status."""
     self._data['derived'] = to_bool(value)
Ejemplo n.º 13
0
 def active(self, value):
     """Set the item's active status."""
     self._data['active'] = to_bool(value)
Ejemplo n.º 14
0
 def derived(self, value):
     """Set the item's derived status."""
     self._data['derived'] = to_bool(value)
Ejemplo n.º 15
0
 def cleared(self, value):
     """Set the item's suspect link status."""
     self.clear(_inverse=not to_bool(value))
Ejemplo n.º 16
0
 def deleted(self, value):
     """Set the item's active status."""
     self._data['deleted'] = to_bool(value)
Ejemplo n.º 17
0
 def normative(self, value):
     """Set the item's normative status."""
     self._data['normative'] = to_bool(value)