photo library planning

This commit is contained in:
dave 2019-07-01 13:53:50 -07:00
parent 1b310f0c4a
commit 80d31eec37
2 changed files with 32 additions and 9 deletions

View File

@ -8,6 +8,7 @@ from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus, User
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
from sqlalchemy import desc from sqlalchemy import desc
from sqlalchemy import func, and_, or_ from sqlalchemy import func, and_, or_
from sqlalchemy.exc import IntegrityError
from photoapp.common import pwhash from photoapp.common import pwhash
import math import math
from urllib.parse import urlparse from urllib.parse import urlparse
@ -33,8 +34,16 @@ class StorageAdapter(object):
# TODO erase the path # TODO erase the path
raise NotImplementedError() raise NotImplementedError()
def dedupe_name(self, path):
# TODO modify and return the passed path such that writing to it does not overwrite an existing file
raise NotImplementedError()
class FilesystemAdapter(StorageAdapter): class FilesystemAdapter(StorageAdapter):
def __init__(self, root):
super().__init__()
self.root = root # root path
def file_exists(self, path): def file_exists(self, path):
# TODO return true/false if the file path exists # TODO return true/false if the file path exists
raise NotImplementedError() raise NotImplementedError()
@ -47,6 +56,10 @@ class FilesystemAdapter(StorageAdapter):
# TODO erase the path # TODO erase the path
raise NotImplementedError() raise NotImplementedError()
def dedupe_name(self, path):
# TODO modify and return the passed path such that writing to it does not overwrite an existing file
raise NotImplementedError()
class S3Adapter(StorageAdapter): class S3Adapter(StorageAdapter):
def file_exists(self, path): def file_exists(self, path):
@ -61,15 +74,20 @@ class S3Adapter(StorageAdapter):
# TODO erase the path # TODO erase the path
raise NotImplementedError() raise NotImplementedError()
def dedupe_name(self, path):
# TODO modify and return the passed path such that writing to it does not overwrite an existing file
raise NotImplementedError()
class GfapiAdapter(StorageAdapter): class GfapiAdapter(StorageAdapter):
pass pass # TODO gluster storage backend
#This is largely duplicated from library.py, but written with intent for later refactoring to support abstract storage. #This is largely duplicated from library.py, but written with intent for later refactoring to support abstract storage.
class LibraryManager(object): class LibraryManager(object):
def __init__(self): def __init__(self, storage):
pass assert isinstance(storage, StorageAdapter)
self.storage = storage
def add_photoset(self, photoset): def add_photoset(self, photoset):
""" """
@ -108,13 +126,14 @@ class LibraryManager(object):
class PhotosApi(object): class PhotosApi(object):
def __init__(self): def __init__(self, library):
self.v1 = PhotosApiV1() self.library = library
self.v1 = PhotosApiV1(self.library)
class PhotosApiV1(object): class PhotosApiV1(object):
def __init__(self): def __init__(self, library):
self.lib = LibraryManager() self.library = library
@cherrypy.expose @cherrypy.expose
def index(self): def index(self):

View File

@ -8,7 +8,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from sqlalchemy import desc from sqlalchemy import desc
from sqlalchemy import func, and_, or_ from sqlalchemy import func, and_, or_
from photoapp.common import pwhash from photoapp.common import pwhash
from photoapp.api import PhotosApi from photoapp.api import PhotosApi, LibraryManager, FilesystemAdapter
from photoapp.dbutils import SAEnginePlugin, SATool from photoapp.dbutils import SAEnginePlugin, SATool
import math import math
from urllib.parse import urlparse from urllib.parse import urlparse
@ -471,7 +471,11 @@ def main():
cherrypy.tools.db = SATool() cherrypy.tools.db = SATool()
SAEnginePlugin(cherrypy.engine, library.engine).subscribe() SAEnginePlugin(cherrypy.engine, library.engine).subscribe()
api = PhotosApi()
library_storage = FilesystemAdapter(args.library)
library_manager = LibraryManager(library_storage)
api = PhotosApi(library_manager)
cherrypy.tree.mount(api, '/api', {'/': {'tools.trailing_slash.on': False, cherrypy.tree.mount(api, '/api', {'/': {'tools.trailing_slash.on': False,
'tools.auth_basic.on': True, 'tools.auth_basic.on': True,
'tools.auth_basic.realm': 'photolib', 'tools.auth_basic.realm': 'photolib',