def links(self): """Add a link from this file to another in the same folder with a matching extension, when such a file exists. """ def dual_exts_for(ext): if ext in self.ext_pairings[0].exts: return self.ext_pairings[1] if ext in self.ext_pairings[1].exts: return self.ext_pairings[0] return _TitledExts((), '') def is_indexed(path): if any(fnmatchcase(basename(path), e) for e in self.tree.ignore_filenames): return False if any(fnmatchcase('/' + path.replace(os.sep, '/'), e) for e in self.tree.ignore_paths): return False return True path_no_ext, ext = splitext(self.path) dual_exts = dual_exts_for(ext) for dual_ext in dual_exts.exts: dual_path = path_no_ext + dual_ext if (isfile(join(self.tree.source_folder, dual_path)) and is_indexed(dual_path)): yield (4, dual_exts.title, [(icon(dual_path), unicode_for_display(basename(dual_path)), browse_file_url(self.tree.name, unicode_for_display(dual_path)))]) # Todo? this 'break' breaks handling of multiple extension # pairings on the same basename. break
def _build_common_file_template(tree, path, date, config): """Return a dictionary of the common required file template parameters. """ return { # Common template variables: 'www_root': config.www_root, 'tree': tree, 'tree_tuples': [(t['name'], url_for('.parallel', tree=t['name'], path=path), t['description']) for t in frozen_configs()], 'generated_date': date, 'google_analytics_key': config.google_analytics_key, 'filters': filter_menu_items(plugins_named( frozen_config(tree)['enabled_plugins'])), # File template variables 'paths_and_names': _linked_pathname(path, tree), 'icon_url': url_for('.static', filename='icons/mimetypes/%s.png' % icon(path)), 'path': path, 'name': basename(path) }
def _file_query_results(self, results, path_highlighters): """Return an iterable of results of a FILE-domain query.""" for file in results: yield (icon(file['path'][0], file.get('is_binary', False)), highlight( file['path'][0], chain.from_iterable(h(file) for h in path_highlighters)), [])
def _file_query_results(self, results, path_highlighters): """Return an iterable of results of a FILE-domain query.""" for file in results: yield (icon(file['path'][0], file.get('is_binary', False)), highlight(file['path'][0], chain.from_iterable( h(file) for h in path_highlighters)), [])
def _icon_class_name(file_doc): """Return a string for the CSS class of the icon for file document.""" if file_doc['is_folder']: return 'folder' class_name = icon(file_doc['name'], file_doc.get('is_binary', [False])[0]) # for small images, we can turn the image into icon via javascript # if bigger than the cutoff, we mark it as too big and don't do this if file_doc['size'] > current_app.dxr_config.max_thumbnail_size: class_name += " too_fat" return class_name
def _build_common_file_template(tree, path, is_binary, date, config): """Return a dictionary of the common required file template parameters. """ return { # Common template variables: 'www_root': config.www_root, 'tree': tree, 'tree_tuples': _tree_tuples('.parallel', path=path), 'generated_date': date, 'google_analytics_key': config.google_analytics_key, 'filters': filter_menu_items( plugins_named(frozen_config(tree)['enabled_plugins'])), # File template variables 'paths_and_names': _linked_pathname(path, tree), 'icon_url': url_for('.static', filename='icons/mimetypes/%s.png' % icon(path, is_binary)), 'path': path, 'name': basename(path) }
def _line_query_results(self, filters, results, path_highlighters): """Return an iterable of results of a LINE-domain query.""" content_highlighters = [f.highlight_content for f in chain.from_iterable(filters) if hasattr(f, 'highlight_content')] # Group lines into files: for path, lines in groupby(results, lambda r: r['path'][0]): lines = list(lines) highlit_path = highlight( path, chain.from_iterable((h(lines[0]) for h in path_highlighters))) icon_for_path = icon(path) yield (icon_for_path, highlit_path, [(line['number'][0], highlight(line['content'][0].rstrip('\n\r'), chain.from_iterable(h(line) for h in content_highlighters))) for line in lines])
def _line_query_results(self, filters, results, path_highlighters): """Return an iterable of results of a LINE-domain query.""" content_highlighters = [ f.highlight_content for f in chain.from_iterable(filters) if hasattr(f, 'highlight_content') ] # Group lines into files: for path, lines in groupby(results, lambda r: r['path'][0]): lines = list(lines) highlit_path = highlight( path, chain.from_iterable((h(lines[0]) for h in path_highlighters))) icon_for_path = icon(path) yield (icon_for_path, highlit_path, [(line['number'][0], highlight( line['content'][0].rstrip('\n\r'), chain.from_iterable( h(line) for h in content_highlighters))) for line in lines])
def _build_common_file_template(tree, path, date, config): """Return a dictionary of the common required file template parameters. """ return { # Common template variables: 'www_root': config.www_root, 'tree': tree, 'tree_tuples': [(t['name'], url_for('.parallel', tree=t['name'], path=path), t['description']) for t in frozen_configs()], 'generated_date': date, 'google_analytics_key': config.google_analytics_key, 'filters': filter_menu_items( plugins_named(frozen_config(tree)['enabled_plugins'])), # File template variables 'paths_and_names': _linked_pathname(path, tree), 'icon': icon(path), 'path': path, 'name': basename(path) }