Skip to content

Commit

Permalink
Merge pull request #93 from OnroerendErfgoed/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
claeyswo authored Dec 22, 2020
2 parents 70b406f + d973899 commit 0608338
Show file tree
Hide file tree
Showing 23 changed files with 353 additions and 301 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: python
sudo: false
python:
- "2.7"
- "3.6"
- "3.8"
env:
- PROJECT=augeias
install:
Expand Down
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.7.0 (22-12-2020)
------------------

- Py3 migratie + library update (#90)

0.6.0 (09-06-2020)
------------------

Expand Down
13 changes: 8 additions & 5 deletions augeias/collections/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
from augeias.stores.PairTreeFileSystemStore import PairTreeFileSystemStore
from augeias.collections.model import Collection
import os

from augeias.collections.model import Collection
from augeias.stores.PairTreeFileSystemStore import PairTreeFileSystemStore


def includeme(config): # pragma: no cover
beeldbank = Collection(name='cheeses', object_store=PairTreeFileSystemStore(os.path.expanduser('~/data/cheeses/data')))
beeldbank = Collection(name='cheeses', object_store=PairTreeFileSystemStore(
os.path.expanduser('~/data/cheeses/data')))
config.registry.collections[beeldbank.name] = beeldbank

besluiten = Collection(name='trees', object_store=PairTreeFileSystemStore(os.path.expanduser('~/data/trees/data')))
besluiten = Collection(name='trees', object_store=PairTreeFileSystemStore(
os.path.expanduser('~/data/trees/data')))
config.registry.collections[besluiten.name] = besluiten
13 changes: 6 additions & 7 deletions augeias/collections/model.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# -*- coding: utf-8 -*-
'''
"""
Contains models that deal with collections.
'''
"""

from augeias.uri import DefaultUriGenerator


class Collection(object):
'''
A collection is a set of containers that can have separate logic and
class Collection:
"""
A collection is a set of containers that can have separate logic and
configuration applied to it.
Currently a collection allows making two chief distinctions:
* Where data whilebe stored, by setting the `object_store`
* How URI's for the collection and it's contents will be generated by
setting a `uri_generator`
'''
"""

def __init__(self, name, object_store, **kwargs):
self.object_store = object_store
Expand Down
3 changes: 1 addition & 2 deletions augeias/scaffolds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from pyramid.scaffolds import PyramidTemplate


class AugeiasTemplate(PyramidTemplate):
_template_dir = 'augeias_scaffold'
summary = 'Create a new Augeias instance.'
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from augeias.stores.PairTreeFileSystemStore import PairTreeFileSystemStore
from augeias.collections.model import Collection

Expand Down
2 changes: 1 addition & 1 deletion augeias/stores/CephStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def create_container(self, container_key):
pass

def delete_container(self, container_key):
pass
pass
68 changes: 34 additions & 34 deletions augeias/stores/PairTreeFileSystemStore.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# -*- coding: utf-8 -*-
'''
"""
This module provide a simple filesystem based store
'''
"""
import datetime
import os
from io import BytesIO
from zipfile import ZipFile

from pairtree import PairtreeStorageFactory, PartNotFoundException, ObjectNotFoundException, id2path
import magic
from pairtree import ObjectNotFoundException
from pairtree import PairtreeStorageFactory
from pairtree import PartNotFoundException
from pairtree import id2path

from augeias.stores.StoreInterface import IStore
from augeias.stores.error import NotFoundException
import os
import magic
import datetime
import sys


class PairTreeFileSystemStore(IStore):
'''
"""
Provides a filesystem based store.
Will store your digital objects on disk using a PairTree.
'''
"""

def __init__(self, store_dir, uri_base='urn:x-vioe:'):
sf = PairtreeStorageFactory()
self.store = sf.get_store(store_dir=store_dir, uri_base=uri_base)
Expand All @@ -31,30 +34,31 @@ def _get_container(self, container_key):
raise NotFoundException

def get_object(self, container_key, object_key):
'''
"""
Retrieve an object from the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to retrieve.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""
container = self._get_container(container_key)
try:
return container.get_bytestream(object_key)
except PartNotFoundException:
raise NotFoundException

def get_object_info(self, container_key, object_key):
'''
"""
Retrieve object info (mimetype, size, time last modification) from the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to retrieve.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""
# todo magic.from_buffer(open(file_path).read(1048576), mime=True) cannot microsoft mimetypes
# https://stackoverflow.com/questions/17779560/django-python-magic-identify-ppt-docx-word-uploaded-file-as-application-zip
file_path = '/'.join([self.store.store_dir, 'pairtree_root', id2path(container_key), object_key])
file_path = '/'.join([self.store.store_dir,
'pairtree_root', id2path(container_key), object_key])
if not os.path.exists(file_path):
raise NotFoundException
file_stat = os.stat(file_path)
Expand All @@ -65,51 +69,51 @@ def get_object_info(self, container_key, object_key):
}

def create_object(self, container_key, object_key, object_data):
'''
"""
Save a new object in the data store
:param str container_key: Key of the container to create an object in.
:param str object_key: Key of the object to create.
:param str object_data: The data for the object to create.
:raises augeias.stores.error.NotFoundException: When the container could not be found.
'''
"""
_validate_data(object_data)
container = self._get_container(container_key)
container.add_bytestream(object_key, object_data)

def update_object(self, container_key, object_key, object_data):
'''
"""
Update an object in the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to update.
:param str object_data: New data for the object.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""
_validate_data(object_data)
container = self.store.get_object(container_key, False)
container.add_bytestream(object_key, object_data)

def list_object_keys_for_container(self, container_key):
'''
"""
List all object keys for a container in the data store.
:param str container_key: Key of the container to list the objects for.
:returns: A list of container keys.
:rtype: lst
:raises augeias.stores.error.NotFoundException: When the container could not be found.
'''
"""
container = self._get_container(container_key)
return container.list_parts()

def delete_object(self, container_key, object_key):
'''
"""
Delete an object from the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to delete.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""
container = self._get_container(container_key)
try:
container.del_file(object_key)
Expand Down Expand Up @@ -138,20 +142,20 @@ def get_container_data(self, container_key, translations=None):
return in_memory_file

def create_container(self, container_key):
'''
"""
Create a new container in the data store.
:param str container_key: Key of the container to create.
'''
"""
self.store.get_object(container_key)

def delete_container(self, container_key):
'''
Delete a container and all it's objects in the data store.
"""
Delete a container and all it's objects in the data store.
:param str container_key: Key of the container to delete.
:raises augeias.stores.error.NotFoundException: When the container could not be found.
'''
"""
try:
self.store.delete_object(container_key)
except ObjectNotFoundException:
Expand All @@ -160,16 +164,12 @@ def delete_container(self, container_key):

def _is_allowed_data(data): # pragma: no cover
# not exhaustive.
python_version = sys.version_info.major
if python_version < 3 and isinstance(data, unicode):
return False

if python_version >= 3 and isinstance(data, str):
if isinstance(data, str):
return False

return True


def _validate_data(data):
if not _is_allowed_data(data):
raise IOError('Data type is not allowed')
raise OSError('Data type is not allowed')
48 changes: 24 additions & 24 deletions augeias/stores/StoreInterface.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,104 @@
# -*- coding: utf-8 -*-
'''
"""
This module defines the interface every store needs to adhere to.
'''
"""

from abc import ABCMeta, abstractmethod


class IStore:
'''
"""
This interface handles object-storage.
Implementations of this interface can be made for different object-storages
Currently this interface is only implemented for PairTreeFileSystemStore
'''
"""
__metaclass__ = ABCMeta

@abstractmethod
def create_object(self, container_key, object_key, object_data):
'''
"""
Save a new object in the data store
:param str container_key: Key of the container to create an object in.
:param str object_key: Key of the object to create.
:param str object_data: The data for the object to create.
:raises augeias.stores.error.NotFoundException: When the container could not be found.
'''
"""

@abstractmethod
def delete_object(self, container_key, object_key):
'''
"""
Delete an object from the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to delete.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""

@abstractmethod
def get_object(self, container_key, object_key):
'''
"""
Retrieve an object from the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to retrieve.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""

@abstractmethod
def get_object_info(self, container_key, object_key):
'''
"""
Retrieve object info (mimetype, size, time last modification) from the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to retrieve.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""

@abstractmethod
def update_object(self, container_key, object_key, object_data):
'''
"""
Update an object in the data store.
:param str container_key: Key of the container that the object lives in.
:param str object_key: Key of the object to update.
:param str object_data: New data for the object.
:raises augeias.stores.error.NotFoundException: When the object or container could not be found.
'''
"""

@abstractmethod
def list_object_keys_for_container(self, container_key):
'''
"""
List all object keys for a container in the data store.
:param str container_key: Key of the container to list the objects for.
:returns: A list of container keys.
:rtype: lst
:raises augeias.stores.error.NotFoundException: When the container could not be found.
'''
"""

@abstractmethod
def get_container_data(self, container_key, translations=None):
'''
"""
Find a container and return a zip file of its contents.
:param container_key: Key of the container which must be retrieved.
:param translations: Dict of object IDs and file names to use for them.
:return: a zip file containing all files of the container.
'''
"""

@abstractmethod
def create_container(self, container_key):
'''
"""
Create a new container in the data store.
:param str container_key: Key of the container to create.
'''
"""

@abstractmethod
def delete_container(self, container_key):
'''
Delete a container and all it's objects in the data store.
"""
Delete a container and all it's objects in the data store.
:param str container_key: Key of the container to delete.
:raises augeias.stores.error.NotFoundException: When the container could not be found.
'''
"""
Loading

0 comments on commit 0608338

Please sign in to comment.