58 |
58 |
|
59 |
59 |
from django.conf import settings
|
60 |
60 |
|
61 |
|
from pithos.backends import connect_backend
|
62 |
61 |
from pithos.backends.base import NotAllowedError
|
63 |
62 |
|
64 |
63 |
|
... | ... | |
75 |
74 |
assert '/' not in container, "Invalid container"
|
76 |
75 |
return 'pithos://%s/%s/%s' % (account, container, object)
|
77 |
76 |
|
|
77 |
|
78 |
78 |
def split_location(location):
|
79 |
79 |
"""Returns (accout, container, object) from a location string"""
|
80 |
80 |
t = location.split('/', 4)
|
... | ... | |
86 |
86 |
pass
|
87 |
87 |
|
88 |
88 |
|
|
89 |
from pithos.backends.util import PithosBackendPool
|
|
90 |
POOL_SIZE = 8
|
|
91 |
_pithos_backend_pool = \
|
|
92 |
PithosBackendPool(POOL_SIZE,
|
|
93 |
db_connection=settings.BACKEND_DB_CONNECTION,
|
|
94 |
block_path=settings.BACKEND_BLOCK_PATH)
|
|
95 |
|
|
96 |
|
|
97 |
def get_pithos_backend():
|
|
98 |
return _pithos_backend_pool.pool_get()
|
|
99 |
|
|
100 |
|
89 |
101 |
class ImageBackend(object):
|
90 |
102 |
"""A wrapper arround the pithos backend to simplify image handling."""
|
91 |
103 |
|
92 |
104 |
def __init__(self, user):
|
93 |
105 |
self.user = user
|
94 |
|
|
|
106 |
|
95 |
107 |
original_filters = warnings.filters
|
96 |
108 |
warnings.simplefilter('ignore') # Suppress SQLAlchemy warnings
|
97 |
|
db_connection = settings.BACKEND_DB_CONNECTION
|
98 |
|
block_path = settings.BACKEND_BLOCK_PATH
|
99 |
|
self.backend = connect_backend(db_connection=db_connection,
|
100 |
|
block_path=block_path)
|
|
109 |
self.backend = get_pithos_backend()
|
101 |
110 |
warnings.filters = original_filters # Restore warnings
|
102 |
|
|
|
111 |
|
103 |
112 |
def _get_image(self, location):
|
104 |
113 |
def format_timestamp(t):
|
105 |
114 |
return strftime('%Y-%m-%d %H:%M:%S', gmtime(t))
|