コード例 #1
0
    def create(cls, **kwargs):
        """Create a new collection

        We intercept the create call"""
        # TODO: Allow name starting or ending with a space ?
#         container = kwargs.get('container', '/').strip()
#         name = kwargs.get('name').strip()
# 
#         kwargs['name'] = name
#         kwargs['container'] = container

        name = kwargs.get('name')
        container = kwargs.get('container', '/')
        kwargs['container'] = container

        d = datetime.now()
        kwargs['create_ts'] = d
        kwargs['modified_ts'] = d

        if 'metadata' in kwargs:
            kwargs['metadata'] = meta_cdmi_to_cassandra(kwargs['metadata'])

        # Check if parent collection exists
        parent = Collection.find_by_path(container)

        if parent is None:
            raise NoSuchCollectionError(container)

        resource = Resource.find_by_path(merge(container, name))

        if resource is not None:
            raise ResourceConflictError(container)
        collection = Collection.find_by_path(merge(container, name))

        if collection is not None:
            raise CollectionConflictError(container)

        res = super(Collection, cls).create(**kwargs)
        res.mqtt_publish('create')

        return res
コード例 #2
0
def is_resource(path):
    """Check if the resource exists"""
    return Resource.find_by_path(path) is not None