refactor configuration variables
This commit is contained in:
parent
27801eef26
commit
759b304cb5
@ -50,9 +50,16 @@ url_map = Map([
|
|||||||
|
|
||||||
class Isso:
|
class Isso:
|
||||||
|
|
||||||
|
SECRET_KEY = ',\x1e\xbaY\xbb\xdf\xe7@\x85\xe3\xd9\xb4A9\xe4G\xa6O'
|
||||||
|
MODERATION = False
|
||||||
|
SQLITE = None
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self, conf):
|
||||||
self.conf = conf
|
|
||||||
self.db = db.SQLite(conf)
|
self.__dict__.update(dict((k, v) for k, v in conf.iteritems() if k.isupper()))
|
||||||
|
|
||||||
|
if self.SQLITE:
|
||||||
|
self.db = db.SQLite(self)
|
||||||
|
|
||||||
def dispatch(self, request, start_response):
|
def dispatch(self, request, start_response):
|
||||||
adapter = url_map.bind_to_environ(request.environ)
|
adapter = url_map.bind_to_environ(request.environ)
|
||||||
|
@ -11,7 +11,7 @@ class Abstract:
|
|||||||
__metaclass__ = abc.ABCMeta
|
__metaclass__ = abc.ABCMeta
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def __init__(self, conf):
|
def __init__(self, app):
|
||||||
return
|
return
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@ -57,10 +57,10 @@ class SQLite(Abstract):
|
|||||||
'text', 'author', 'email', 'website', 'parent', 'mode'
|
'text', 'author', 'email', 'website', 'parent', 'mode'
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, conf):
|
def __init__(self, app):
|
||||||
|
|
||||||
self.dbpath = conf['SQLITE']
|
self.dbpath = app.SQLITE
|
||||||
self.mode = 1 if conf.get('MODERATION') else 0
|
self.mode = 1 if app.MODERATION else 0
|
||||||
|
|
||||||
with sqlite3.connect(self.dbpath) as con:
|
with sqlite3.connect(self.dbpath) as con:
|
||||||
sql = ('main.comments (id INTEGER NOT NULL, path VARCHAR(255) NOT NULL,'
|
sql = ('main.comments (id INTEGER NOT NULL, path VARCHAR(255) NOT NULL,'
|
||||||
|
@ -5,6 +5,7 @@ import time
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import isso
|
||||||
from isso.models import Comment
|
from isso.models import Comment
|
||||||
from isso.db import SQLite
|
from isso.db import SQLite
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class TestSQLite(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
fd, self.path = tempfile.mkstemp()
|
fd, self.path = tempfile.mkstemp()
|
||||||
self.db = SQLite({'SQLITE': self.path})
|
self.db = SQLite(isso.Isso({'SQLITE': self.path}))
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user