md5.update(data + ('\x00' * pad))
return md5.hexdigest().lower()
+def get_backend():
+ backend = connect_backend(db_module=settings.BACKEND_DB_MODULE,
+ db_connection=settings.BACKEND_DB_CONNECTION,
+ block_module=settings.BACKEND_BLOCK_MODULE,
+ block_path=settings.BACKEND_BLOCK_PATH)
+ backend.default_policy['quota'] = settings.BACKEND_QUOTA
+ backend.default_policy['versioning'] = settings.BACKEND_VERSIONING
+ return backend
+
def update_request_headers(request):
# Handle URL-encoded keys and values.
# Handle URL-encoded keys and values.
# Fill in custom request variables.
request.serialization = request_serialization(request, format_allowed)
- request.backend = connect_backend()
+ request.backend = get_backend()
response = func(request, *args, **kwargs)
update_response_headers(request, response)
import warnings
-from django.conf import settings
-
from modular import ModularBackend
-def connect_backend():
+def connect_backend(**kwargs):
# Suppress mysql warnings.
original_filters = warnings.filters[:]
warnings.simplefilter('ignore')
try:
- backend = ModularBackend(settings.BACKEND_DB_MODULE,
- settings.BACKEND_DB_CONNECTION,
- settings.BACKEND_BLOCK_MODULE,
- settings.BACKEND_BLOCK_PATH)
+ backend = ModularBackend(**kwargs)
finally:
# Restore warnings.
warnings.filters = original_filters
- # Set defaults.
- backend.default_policy['quota'] = settings.DEFAULT_QUOTA
- backend.default_policy['versioning'] = settings.DEFAULT_VERSIONING
-
return backend
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
+# Default setting for new accounts.
+DEFAULT_QUOTA = 0 # No quota.
+DEFAULT_VERSIONING = 'auto'
+
+
class NotAllowedError(Exception):
pass
'default_policy': A dictionary with default policy settings
"""
- def __init__(self, db_module, db_connection, block_module, block_path):
- """Initialize backend with supplied modules and options."""
- pass
-
def close(self):
"""Close the backend connection."""
pass
# copyright notice, this list of conditions and the following
# disclaimer.
#
-# 2. Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the following
+# 2. Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
import logging
import binascii
-from base import NotAllowedError, QuotaError, BaseBackend
+from base import DEFAULT_QUOTA, DEFAULT_VERSIONING, NotAllowedError, QuotaError, BaseBackend
from pithos.lib.hashmap import HashMap
+# Default modules and settings.
+DEFAULT_DB_MODULE = 'pithos.backends.lib.sqlalchemy'
+DEFAULT_DB_CONNECTION = 'sqlite:///backend.db'
+DEFAULT_BLOCK_MODULE = 'pithos.backends.lib.hashfiler'
+DEFAULT_BLOCK_PATH = 'data/'
+
( CLUSTER_NORMAL, CLUSTER_HISTORY, CLUSTER_DELETED ) = range(3)
inf = float('inf')
Uses modules for SQL functions and storage.
"""
- def __init__(self, db_module, db_connection, block_module, block_path):
- db_module = db_module or 'pithos.backends.lib.sqlalchemy'
- block_module = block_module or 'pithos.backends.lib.hashfiler'
+ def __init__(self, db_module=None, db_connection=None, block_module=None, block_path=None):
+ db_module = db_module or DEFAULT_DB_MODULE
+ db_connection = db_connection or DEFAULT_DB_CONNECTION
+ block_module = block_module or DEFAULT_BLOCK_MODULE
+ block_path = block_path or DEFAULT_BLOCK_PATH
self.hash_algorithm = 'sha256'
self.block_size = 4 * 1024 * 1024 # 4MB
- self.default_policy = {'quota': 0, 'versioning': 'auto'}
+ self.default_policy = {'quota': DEFAULT_QUOTA, 'versioning': DEFAULT_VERSIONING}
__import__(db_module)
self.db_module = sys.modules[db_module]
BACKEND_BLOCK_PATH = join(PROJECT_PATH, 'data/')
# Default setting for new accounts.
-DEFAULT_QUOTA = 50 * 1024 * 1024 * 1024
-DEFAULT_VERSIONING = 'auto'
\ No newline at end of file
+BACKEND_QUOTA = 50 * 1024 * 1024 * 1024
+BACKEND_VERSIONING = 'auto'