Commit d15969b6 authored by Antony Chazapis's avatar Antony Chazapis

Make modular backend load modules dynamically.

parent 58b36668
......@@ -35,7 +35,6 @@ from django.conf import settings
from simple import SimpleBackend
from modular import ModularBackend
from modular_alchemy import AlchemyBackend
backend = None
options = getattr(settings, 'BACKEND', None)
......
from dbwrapper import DBWrapper
from node import Node
from permissions import Permissions
from policy import Policy
__all__ = ["DBWrapper", "Node", "Permissions", "Policy"]
# Copyright 2011 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# 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
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from dbwrapper import DBWrapper
from node import Node
from permissions import Permissions
from policy import Policy
__all__ = ["DBWrapper", "Node", "Permissions", "Policy"]
# Copyright 2011 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# 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
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
import sqlite3
class DBWrapper(object):
"""Database connection wrapper."""
def __init__(self, db):
self.conn = sqlite3.connect(db, check_same_thread=False)
def execute(self):
self.conn.execute('begin deferred')
def commit(self):
self.conn.commit()
def rollback(self):
self.conn.rollback()
This diff is collapsed.
......@@ -72,19 +72,18 @@ class SimpleBackend(BaseBackend):
# TODO: Create account if not present in all functions.
def __init__(self, db, db_options):
def __init__(self, path, db):
self.hash_algorithm = 'sha256'
self.block_size = 4 * 1024 * 1024 # 4MB
self.default_policy = {'quota': 0, 'versioning': 'auto'}
basepath = os.path.split(db)[0]
if basepath and not os.path.exists(basepath):
os.makedirs(basepath)
if not os.path.isdir(basepath):
raise RuntimeError("Cannot open database at '%s'" % (db,))
if path and not os.path.exists(path):
os.makedirs(path)
if not os.path.isdir(path):
raise RuntimeError("Cannot open path '%s'" % (path,))
self.con = sqlite3.connect(basepath + '/db', check_same_thread=False)
self.con = sqlite3.connect(db, check_same_thread=False)
sql = '''pragma foreign_keys = on'''
self.con.execute(sql)
......@@ -123,11 +122,11 @@ class SimpleBackend(BaseBackend):
self.con.commit()
params = {'blocksize': self.block_size,
'blockpath': basepath + '/blocks',
'blockpath': os.path.join(path + '/blocks'),
'hashtype': self.hash_algorithm}
self.blocker = Blocker(**params)
params = {'mappath': basepath + '/maps',
params = {'mappath': os.path.join(path + '/maps'),
'namelen': self.blocker.hashlen}
self.mapper = Mapper(**params)
......
......@@ -39,13 +39,7 @@ PROJECT_PATH = os.path.dirname(os.path.abspath(__file__)) + '/'
DEBUG = True
TEMPLATE_DEBUG = DEBUG
# A quick-n-dirty way to know if we're running unit tests
import sys
TEST = False
if len(sys.argv) >= 2:
if os.path.basename(sys.argv[0]) == 'manage.py' and \
(sys.argv[1] == 'test' or sys.argv[1] == 'hudson'):
TEST = True
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
......@@ -65,15 +59,20 @@ DATABASES = {
}
# The backend to use and its initilization options.
dbuser = ''
dbpass = ''
dbhost = ''
dbname = ''
db_options = (dbuser, dbpass, dbhost, dbname,)
if TEST:
BACKEND = ('SimpleBackend', (os.path.join(PROJECT_PATH, 'data/test/'), db_options,))
else:
BACKEND = ('SimpleBackend', (os.path.join(PROJECT_PATH, 'data/pithos/'), db_options,))
# Simple.
#backend_path = os.path.join(PROJECT_PATH, 'data/pithos/')
#backend_db = os.path.join(PROJECT_PATH, 'data/pithos/db')
#BACKEND = ('SimpleBackend', (backend_path, backend_db))
# Modular.
backend_module = 'pithos.backends.lib.sqlite'
backend_path = os.path.join(PROJECT_PATH, 'data/pithos/')
backend_db = os.path.join(PROJECT_PATH, 'data/pithos/db')
#backend_module = 'pithos.backends.lib.sqlalchemy'
#backend_path = os.path.join(PROJECT_PATH, 'data/pithos/')
#backend_db = 'postgresql://user:pass@host/db'
BACKEND = ('ModularBackend', (backend_module, backend_path, backend_db))
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment