blob: 740c5977acd28bfbe147168bbfbe526cc4ec5949 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
"""environment.py
Establish data / cache file paths, and configurations,
bootstrap fixture data if necessary.
"""
import caching_query
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from beaker import cache
import os
# Beaker CacheManager. A home base for cache configurations.
cache_manager = cache.CacheManager()
# scoped_session. Apply our custom CachingQuery class to it,
# using a callable that will associate the cache_manager
# with the Query.
Session = scoped_session(
sessionmaker(
query_cls=caching_query.query_callable(cache_manager)
)
)
# global declarative base class.
Base = declarative_base()
root = "./beaker_data/"
if not os.path.exists(root):
raw_input("Will create datafiles in %r.\n"
"To reset the cache + database, delete this directory.\n"
"Press enter to continue.\n" % root
)
os.makedirs(root)
dbfile = os.path.join(root, "beaker_demo.db")
engine = create_engine('sqlite:///%s' % dbfile, echo=True)
Session.configure(bind=engine)
# configure the "default" cache region.
cache_manager.regions['default'] ={
# using type 'file' to illustrate
# serialized persistence. In reality,
# use memcached. Other backends
# are much, much slower.
'type':'file',
'data_dir':root,
'expire':3600,
# set start_time to current time
# to re-cache everything
# upon application startup
#'start_time':time.time()
}
installed = False
def bootstrap():
global installed
import fixture_data
if not os.path.exists(dbfile):
fixture_data.install()
installed = True
|