示例#1
0
def rev(tree, revision, path):
    """Display a page showing the file at path at specified revision by
    obtaining the contents from version control.
    """
    config = current_app.dxr_config
    tree_config = config.trees[tree]
    abs_path = join(tree_config.source_folder, path)
    contents = file_contents_at_rev(abs_path, revision)
    if contents is not None:
        image_rev = None
        if is_binary_image(path):
            is_text = False
            contents = ''
            image_rev = revision
        else:
            is_text, contents = decode_data(contents, tree_config.source_encoding)
            if not is_text:
                contents = ''
            elif is_textual_image(path):
                image_rev = revision

        # We do some wrapping to mimic the JSON returned by an ES lines query.
        return _browse_file(tree,
                            path,
                            [{'content': line} for line in split_content_lines(contents)],
                            {},
                            config,
                            not is_text,
                            contents=contents,
                            image_rev=image_rev)
    else:
        raise NotFound
示例#2
0
文件: app.py 项目: zz22zz222/dxr
def raw_rev(tree, revision, path):
    """Send raw data at path from tree at the given revision, for binary things
    like images."""
    if not is_binary_image(path) and not is_textual_image(path):
        raise NotFound

    config = current_app.dxr_config
    tree_config = config.trees[tree]
    data = file_contents_at_rev(tree_config.source_folder, path, revision)
    if data is None:
        raise NotFound
    data_file = StringIO(data)
    return send_file(data_file, mimetype=guess_type(path)[0])
示例#3
0
文件: app.py 项目: modulexcite/dxr
def rev(tree, revision, path):
    """Display a page showing the file at path at specified revision by
    obtaining the contents from version control.
    """
    config = current_app.dxr_config
    tree_config = config.trees[tree]
    abs_path = join(tree_config.source_folder, path)
    contents = file_contents_at_rev(abs_path, revision)
    if contents is not None and is_text(contents):
        contents = contents.decode(tree_config.source_encoding)
        # We do some wrapping to mimic the JSON returned by an ES lines query.
        return _browse_file(tree,
                            path, [{
                                'content': line
                            } for line in contents.splitlines(True)], {},
                            config,
                            contents=contents)
    else:
        raise NotFound
示例#4
0
文件: app.py 项目: gartung/dxr
def rev(tree, revision, path):
    """Display a page showing the file at path at specified revision by
    obtaining the contents from version control.
    """
    config = current_app.dxr_config
    tree_config = config.trees[tree]
    abs_path = join(tree_config.source_folder, path)
    contents = file_contents_at_rev(abs_path, revision)
    if contents is not None and is_text(contents):
        contents = contents.decode(tree_config.source_encoding)
        # We do some wrapping to mimic the JSON returned by an ES lines query.
        return _browse_file(tree,
                            path,
                            [{'content': line} for line in contents.splitlines(True)],
                            {},
                            config,
                            contents=contents)
    else:
        raise NotFound