photo library planning
This commit is contained in:
parent
1b310f0c4a
commit
80d31eec37
@ -8,6 +8,7 @@ from photoapp.types import Photo, PhotoSet, Tag, TagItem, PhotoStatus, User
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy import func, and_, or_
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from photoapp.common import pwhash
|
||||
import math
|
||||
from urllib.parse import urlparse
|
||||
@ -33,8 +34,16 @@ class StorageAdapter(object):
|
||||
# TODO erase the path
|
||||
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):
|
||||
def __init__(self, root):
|
||||
super().__init__()
|
||||
self.root = root # root path
|
||||
|
||||
def file_exists(self, path):
|
||||
# TODO return true/false if the file path exists
|
||||
raise NotImplementedError()
|
||||
@ -47,6 +56,10 @@ class FilesystemAdapter(StorageAdapter):
|
||||
# TODO erase the path
|
||||
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):
|
||||
def file_exists(self, path):
|
||||
@ -61,15 +74,20 @@ class S3Adapter(StorageAdapter):
|
||||
# TODO erase the path
|
||||
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):
|
||||
pass
|
||||
pass # TODO gluster storage backend
|
||||
|
||||
|
||||
#This is largely duplicated from library.py, but written with intent for later refactoring to support abstract storage.
|
||||
class LibraryManager(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, storage):
|
||||
assert isinstance(storage, StorageAdapter)
|
||||
self.storage = storage
|
||||
|
||||
def add_photoset(self, photoset):
|
||||
"""
|
||||
@ -108,13 +126,14 @@ class LibraryManager(object):
|
||||
|
||||
|
||||
class PhotosApi(object):
|
||||
def __init__(self):
|
||||
self.v1 = PhotosApiV1()
|
||||
def __init__(self, library):
|
||||
self.library = library
|
||||
self.v1 = PhotosApiV1(self.library)
|
||||
|
||||
|
||||
class PhotosApiV1(object):
|
||||
def __init__(self):
|
||||
self.lib = LibraryManager()
|
||||
def __init__(self, library):
|
||||
self.library = library
|
||||
|
||||
@cherrypy.expose
|
||||
def index(self):
|
||||
|
@ -8,7 +8,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy import func, and_, or_
|
||||
from photoapp.common import pwhash
|
||||
from photoapp.api import PhotosApi
|
||||
from photoapp.api import PhotosApi, LibraryManager, FilesystemAdapter
|
||||
from photoapp.dbutils import SAEnginePlugin, SATool
|
||||
import math
|
||||
from urllib.parse import urlparse
|
||||
@ -471,7 +471,11 @@ def main():
|
||||
|
||||
cherrypy.tools.db = SATool()
|
||||
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,
|
||||
'tools.auth_basic.on': True,
|
||||
'tools.auth_basic.realm': 'photolib',
|
||||
|
Loading…
x
Reference in New Issue
Block a user