Example #1
0
 def get_object(self, location):
     if len(location) != self._num_levels:
         raise base.InvalidLocationQuery(location)
     entity = self._db.Location.get_by_db_location(location)
     if not entity:
         raise base.LocationDoesNotExist(location)
     return entity.object.as_db_object_info()
Example #2
0
 def list_location(self, location, filter=None):
     # XXX Implement filter.
     if len(location) >= self._num_levels:
         raise base.InvalidLocationQuery(location)
     entity = self._db.Location.get_by_db_location(location)
     if not entity:
         raise base.LocationDoesNotExist(location)
     return (x.as_db_location_info() for x in entity.children)
Example #3
0
 def from_db_location(cls, loc: base.Location,
                      metadata: Dict) -> 'Location':
     now = datetime.utcnow()
     parent = cls.get_by_db_location(loc.parent)
     if not parent:
         raise base.LocationDoesNotExist(loc.parent)
     entity = cls(name=loc[-1],
                  parent=parent,
                  metadata=metadata,
                  date_created=now,
                  date_updated=now)
     return entity
Example #4
0
    def delete_location(self, location, recursive):
        if len(location) > self._num_levels:
            raise base.InvalidLocationQuery(location)

        entity = self._db.Location.get_by_db_location(location)
        if not entity:
            raise base.LocationDoesNotExist(location)

        if entity.children and not recursive:
            raise base.LocationHasChildren(location)

        objects = [x.as_db_object_info() for x in entity.collect_objects()]
        if len(location) == 0:
            # The root location can not be deleted, but it's children can be.
            entity.children.select().delete()
        else:
            if not entity:
                raise base.LocationDoesNotExist(location)
            entity.delete()

        return objects
Example #5
0
 def list_objects(self, location, filter=None):
     # XXX Implement filter.
     if len(location) not in (self._num_levels, self._num_levels - 1):
         raise base.InvalidLocationQuery(location)
     entity = self._db.Location.get_by_db_location(location)
     if not entity:
         raise base.LocationDoesNotExist(location)
     if len(location) == self._num_levels:
         yield entity.object.as_db_object_info()
     else:
         yield from (x.object.as_db_object_info() for x in entity.children
                     if x.object)