Commit a349a8f6 authored by Laurent Bachelier's avatar Laurent Bachelier

Move DATA_PATHS to Storage

This will allow the user to easily overload templates and assets,
for only the current ass2m root.

Another benefit is that we are now able to get the DATA_PATHS without a

It is possible to get the DATA_PATHS without a directory though, by
getting Storage.DATA_PATHS (this is only useful for errors about the
ass2m root).
parent eb0938f7
......@@ -53,7 +53,7 @@ class AssetAction(Action):
self.ctx.res = HTTPPreconditionFailed()
def find_file(self, filename):
paths = [os.path.join(path, 'assets') for path in self.ctx.DATA_PATHS]
paths = [os.path.join(path, 'assets') for path in]
for path in paths:
realpath = os.path.join(path, filename)
if os.path.isfile(realpath):
......@@ -43,9 +43,6 @@ __all__ = ['ViewAction', 'Action', 'Server', 'FileApp']
class Context(object):
SANITIZE_REGEXP = re.compile(r'/[%s+r]+/|\\+|/+' % re.escape(r'/.'))
DATA_PATHS = [os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')),
def __init__(self, router, environ, start_response):
self.router = router
......@@ -112,7 +109,8 @@ class Context(object):
def _init_templates(self):
paths = [os.path.join(path, 'templates') for path in self.DATA_PATHS]
data_paths = if else Storage.DATA_PATHS
paths = [os.path.join(path, 'templates') for path in data_paths]
imports = ['from ass2m.filters import compact as cpt, quote_and_decode_url as U',
'from paste.url import URL']
self.lookup = TemplateLookup(directories=paths, collection_size=20,
......@@ -59,9 +59,13 @@ class GroupsConfig(IObject, dict):
class Storage(object):
DIRNAME = '.ass2m'
DATA_PATHS = [os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'data')),
def __init__(self, path):
self.path = path
self.DATA_PATHS.insert(0, os.path.realpath(os.path.join(self.path, 'data')))
def root(self):
from __future__ import with_statement
from import Storage
from ass2m.server import Server, Context
from ass2m.server import Server
from unittest import TestCase
from webtest import TestApp
......@@ -22,15 +22,15 @@ class AssetsTest(TestCase):
with open(os.path.join(datapath, 'assets', 'main.css'), 'w') as f:
f.write('body { background-color: pink; }')
# monkeypatching
self.data_paths = Context.DATA_PATHS
Context.DATA_PATHS.insert(0, datapath)
Context.DATA_PATHS.insert(0, os.path.join(self.root, 'doesnotexist'))
self.data_paths = Storage.DATA_PATHS
Storage.DATA_PATHS.insert(0, datapath)
Storage.DATA_PATHS.insert(0, os.path.join(self.root, 'doesnotexist'))
def tearDown(self):
if self.root:
# demonkeypatching
Context.DATA_PATHS = self.data_paths
Storage.DATA_PATHS = self.data_paths
def test_getAsset(self):
res ='/?action=asset&file=main.css', status=200)
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