def __init__(self, root):
        self.app_root = path.dirname(root)
        self.files = ResourceManager(base=root)
        self.files.add_path(path='static/')
        self.files.add_path(path='static/json/')

        self.environment = Environment(loader=FileSystemLoader(
            searchpath=path.join(self.app_root, 'template')))
Example #2
0
 def test_path_create(self):
     import tempfile, shutil
     tempdir = tempfile.mkdtemp()
     try:
         rm = ResourceManager()
         exists = rm.add_path('./test/', base=tempdir)
         self.assertEqual(exists, False)
         exists = rm.add_path('./test2/', base=tempdir, create=True)
         self.assertEqual(exists, True)
     finally:
         shutil.rmtree(tempdir)
Example #3
0
 def test_path_create(self):
     import tempfile, shutil
     tempdir = tempfile.mkdtemp()
     try:
         rm = ResourceManager()
         exists = rm.add_path('./test/', base=tempdir)
         self.assertEqual(exists, False)
         exists = rm.add_path('./test2/', base=tempdir, create=True)
         self.assertEqual(exists, True)
     finally:
         shutil.rmtree(tempdir)
Example #4
0
 def test_get(self):
     rm = ResourceManager()
     rm.add_path('/first/')
     rm.add_path(__file__)
     rm.add_path('/last/')
     self.assertEqual(None, rm.lookup('notexist.txt'))
     self.assertEqual(__file__, rm.lookup(os.path.basename(__file__)))
Example #5
0
 def test_get(self):
     rm = ResourceManager()
     rm.add_path('/first/')
     rm.add_path(__file__)
     rm.add_path('/last/')
     self.assertEqual(None, rm.lookup('notexist.txt'))
     self.assertEqual(__file__, rm.lookup(os.path.basename(__file__)))
    def __init__(self, root):
        self.app_root = path.dirname(root)
        self.files = ResourceManager(base=root)
        self.files.add_path(path='static/')
        self.files.add_path(path='static/json/')

        self.environment = Environment(
            loader=FileSystemLoader(
                searchpath=path.join(self.app_root, 'template')))
Example #7
0
    def test_root_path(self):
        tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
        for test in tests:
            rm = ResourceManager()
            rm.add_path('./baz/', test)
            self.assertEqual(rm.path, ['/foo/bar/baz/'])

        for test in tests:
            rm = ResourceManager()
            rm.add_path('baz/', test)
            self.assertEqual(rm.path, ['/foo/bar/baz/'])
Example #8
0
    def test_path_absolutize(self):
        tests = ('./foo/bar/', './foo/bar/baz', './foo/baz/../bar/blub')
        abspath = os.path.abspath('./foo/bar/') + os.sep
        for test in tests:
            rm = ResourceManager()
            rm.add_path(test)
            self.assertEqual(rm.path, [abspath])

        for test in tests:
            rm = ResourceManager()
            rm.add_path(test[2:])
            self.assertEqual(rm.path, [abspath])
class Site(object):
    def __init__(self, root):
        self.app_root = path.dirname(root)
        self.files = ResourceManager(base=root)
        self.files.add_path(path='static/')
        self.files.add_path(path='static/json/')

        self.environment = Environment(loader=FileSystemLoader(
            searchpath=path.join(self.app_root, 'template')))

    @property
    def _site_cfg(self):
        json_file_name = self.files.lookup('site.json')
        with open(json_file_name) as json_file:
            ret = load(json_file)
        self.environment.globals['site'] = ret
        return ret

    @property
    def apps(self):
        return self._site_cfg['apps']
class Site(object):
    def __init__(self, root):
        self.app_root = path.dirname(root)
        self.files = ResourceManager(base=root)
        self.files.add_path(path='static/')
        self.files.add_path(path='static/json/')

        self.environment = Environment(
            loader=FileSystemLoader(
                searchpath=path.join(self.app_root, 'template')))

    @property
    def _site_cfg(self):
        json_file_name = self.files.lookup('site.json')
        with open(json_file_name) as json_file:
            ret = load(json_file)
        self.environment.globals['site'] = ret
        return ret

    @property
    def apps(self):
        return self._site_cfg['apps']
Example #11
0
    def test_root_path(self):
        tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
        for test in tests:
            rm = ResourceManager()
            rm.add_path('./baz/', test)
            self.assertEqual(rm.path, ['/foo/bar/baz/'])

        for test in tests:
            rm = ResourceManager()
            rm.add_path('baz/', test)
            self.assertEqual(rm.path, ['/foo/bar/baz/'])
Example #12
0
    def test_path_absolutize(self):
        tests = ('./foo/bar/', './foo/bar/baz', './foo/baz/../bar/blub')
        abspath = os.path.abspath('./foo/bar/') + os.sep
        for test in tests:
            rm = ResourceManager()
            rm.add_path(test)
            self.assertEqual(rm.path, [abspath])

        for test in tests:
            rm = ResourceManager()
            rm.add_path(test[2:])
            self.assertEqual(rm.path, [abspath])
Example #13
0
 def test_path_order(self):
     rm = ResourceManager()
     rm.add_path('/middle/')
     rm.add_path('/first/', index=0)
     rm.add_path('/last/')
     self.assertEqual(rm.path, ['/first/', '/middle/', '/last/'])
Example #14
0
 def test_path_unique(self):
     tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
     rm = ResourceManager()
     [rm.add_path(test) for test in tests]
     self.assertEqual(rm.path, ['/foo/bar/'])
Example #15
0
 def test_path_normalize(self):
     tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
     for test in tests:
         rm = ResourceManager()
         rm.add_path(test)
         self.assertEqual(rm.path, ['/foo/bar/'])
Example #16
0
 def test_open(self):
     rm = ResourceManager()
     rm.add_path(__file__)
     fp = rm.open(os.path.basename(__file__))
     self.assertEqual(fp.read(), open(__file__).read())
Example #17
0
 def test_path_order(self):
     rm = ResourceManager()
     rm.add_path('/middle/')
     rm.add_path('/first/', index=0)
     rm.add_path('/last/')
     self.assertEqual(rm.path, ['/first/', '/middle/', '/last/'])
Example #18
0
 def test_path_unique(self):
     tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
     rm = ResourceManager()
     [rm.add_path(test) for test in tests]
     self.assertEqual(rm.path, ['/foo/bar/'])
Example #19
0
 def test_path_normalize(self):
     tests = ('/foo/bar/', '/foo/bar/baz', '/foo/baz/../bar/blub')
     for test in tests:
         rm = ResourceManager()
         rm.add_path(test)
         self.assertEqual(rm.path, ['/foo/bar/'])
Example #20
0
 def test_open(self):
     rm = ResourceManager()
     rm.add_path(__file__)
     fp = rm.open(os.path.basename(__file__))
     self.assertEqual(fp.read(), open(__file__).read())