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()
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
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
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
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
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
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)