예제 #1
0
 def test_findfile_cache(self):
     eh = logging_handler('blazeweb.hierarchy')
     findfile('templates/forcache.txt')
     dmesgs = ''.join(eh.messages['debug'])
     assert 'in cache' not in dmesgs, dmesgs
     eh.reset()
     findfile('templates/forcache.txt')
     dmesgs = ''.join(eh.messages['debug'])
     assert 'in cache' in dmesgs, dmesgs
     eh.reset()
예제 #2
0
 def test_findfile_cache(self):
     eh = logging_handler('blazeweb.hierarchy')
     findfile('templates/forcache.txt')
     dmesgs = ''.join(eh.messages['debug'])
     assert 'in cache' not in dmesgs, dmesgs
     eh.reset()
     findfile('templates/forcache.txt')
     dmesgs = ''.join(eh.messages['debug'])
     assert 'in cache' in dmesgs, dmesgs
     eh.reset()
예제 #3
0
    def test_app_findfile(self):
        fullpath = findfile('templates/blank.txt')
        expected = path.join('nlsupporting', 'templates', 'blank.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('templates/innl.txt')
        expected = path.join('newlayout', 'templates', 'innl.txt')
        assert fullpath.endswith(expected), fullpath

        try:
            findfile('templates/notthere.txt')
            assert False
        except FileNotFound:
            pass
예제 #4
0
    def test_app_findfile(self):
        fullpath = findfile('templates/blank.txt')
        expected = path.join('nlsupporting', 'templates', 'blank.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('templates/innl.txt')
        expected = path.join('newlayout', 'templates', 'innl.txt')
        assert fullpath.endswith(expected), fullpath

        try:
            findfile('templates/notthere.txt')
            assert False
        except FileNotFound:
            pass
예제 #5
0
 def loader(pathpart):
     if pathpart is None:
         self.debug(pathpart, 'pathpart is None')
         return None, None
     if not pathpart.count('/'):
         self.debug(pathpart, 'pathpart had no slashes')
         return None, None
     type, locpath = pathpart.split('/', 1)
     if not locpath:
         self.debug(pathpart, 'pathpart had type, but not locpath')
         return None, None
     if type not in ('app', 'component'):
         self.debug(pathpart, 'type was not "app" or "component"')
         return None, None
     if type == 'component':
         if not locpath.count('/'):
             self.debug(pathpart, 'component type, but locpath had no slashes')
             return None, None
         component, locpath = locpath.split('/', 1)
     # look in the static directory
     locpath = 'static/' + locpath
     if type == 'app':
         endpoint = locpath
     else:
         endpoint = '%s:%s' % (component, locpath)
     try:
         fpath = findfile(endpoint)
         return path.basename(fpath), self._opener(fpath)
     except FileNotFound:
         self.debug(pathpart, 'endpoint "%s" not found' % endpoint)
         return None, None
예제 #6
0
 def loader(pathpart):
     if pathpart is None:
         self.debug(pathpart, 'pathpart is None')
         return None, None
     if not pathpart.count('/'):
         self.debug(pathpart, 'pathpart had no slashes')
         return None, None
     type, locpath = pathpart.split('/', 1)
     if not locpath:
         self.debug(pathpart, 'pathpart had type, but not locpath')
         return None, None
     if type not in ('app', 'component'):
         self.debug(pathpart, 'type was not "app" or "component"')
         return None, None
     if type == 'component':
         if not locpath.count('/'):
             self.debug(pathpart,
                        'component type, but locpath had no slashes')
             return None, None
         component, locpath = locpath.split('/', 1)
     # look in the static directory
     locpath = 'static/' + locpath
     if type == 'app':
         endpoint = locpath
     else:
         endpoint = '%s:%s' % (component, locpath)
     try:
         fpath = findfile(endpoint)
         return path.basename(fpath), self._opener(fpath)
     except FileNotFound:
         self.debug(pathpart, 'endpoint "%s" not found' % endpoint)
         return None, None
예제 #7
0
    def test_component_findfile(self):
        fullpath = findfile('news:templates/srcnews.txt')
        expected = path.join('newlayout', 'components', 'news', 'templates', 'srcnews.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/ncomp1.txt')
        expected = path.join('newscomp1', 'templates', 'ncomp1.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/ncomp2.txt')
        expected = path.join('newscomp2', 'templates', 'ncomp2.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/supporting_news_src.txt')
        expected = path.join('nlsupporting', 'components', 'news', 'templates',
                             'supporting_news_src.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/ncomp3.txt')
        expected = path.join('newscomp3', 'templates', 'ncomp3.txt')
        assert fullpath.endswith(expected), fullpath

        try:
            findfile('news:templates/notthere.txt')
            assert False
        except FileNotFound:
            pass
예제 #8
0
    def test_component_findfile(self):
        fullpath = findfile('news:templates/srcnews.txt')
        expected = path.join('newlayout', 'components', 'news', 'templates',
                             'srcnews.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/ncomp1.txt')
        expected = path.join('newscomp1', 'templates', 'ncomp1.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/ncomp2.txt')
        expected = path.join('newscomp2', 'templates', 'ncomp2.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/supporting_news_src.txt')
        expected = path.join('nlsupporting', 'components', 'news', 'templates',
                             'supporting_news_src.txt')
        assert fullpath.endswith(expected), fullpath

        fullpath = findfile('news:templates/ncomp3.txt')
        expected = path.join('newscomp3', 'templates', 'ncomp3.txt')
        assert fullpath.endswith(expected), fullpath

        try:
            findfile('news:templates/notthere.txt')
            assert False
        except FileNotFound:
            pass
예제 #9
0
파일: jinja.py 프로젝트: blazelibs/blazeweb
 def find_template_path(self, endpoint):
     # try module level first
     try:
         component, template = split_endpoint(endpoint)
         endpoint = path.join('templates', template)
         if component:
             endpoint = '%s:%s' % (component, endpoint)
         return findfile(endpoint)
     except FileNotFound:
         pass
예제 #10
0
def yield_blocks_from_dir(rel_path):
    """
        yields blocks of SQL from sql files in a directory

        rel_path: a path relative to the app's root
    """
    dirpath = findfile(rel_path)
    if not path.isdir(dirpath):
        raise NotDirectoryExc('path found, but "%s" is not a directory' %
                              rel_path)
    for dirname, _, filenames in walk(dirpath):
        filenames.sort()
        for filename in filenames:
            if not filename.endswith('.sql'):
                continue
            with open(path.join(dirname, filename), 'rb') as fh:
                sql_file_contents = fh.read().decode()
            line1, _ = sql_file_contents.split('\n', 1)
            if 'dialect-require:' not in line1 or db.engine.dialect.name in line1:
                for sql_block in yield_sql_blocks(sql_file_contents):
                    yield filename, sql_block
예제 #11
0
def _run_file_sql(relative_sql_path):
    full_path = findfile(relative_sql_path)
    with open(full_path, 'rb') as fh:
        sql_file_contents = fh.read().decode()
    for sql_block in yield_sql_blocks(sql_file_contents):
        _execute_sql_block(sql_block)