Ejemplo n.º 1
0
Archivo: app.py Proyecto: 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
Ejemplo n.º 2
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 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
Ejemplo n.º 3
0
Archivo: build.py Proyecto: bozzmob/dxr
def file_contents(path, encoding_guess):  # TODO: Make accessible to TreeToIndex.post_build.
    """Return the unicode contents of a file if we can figure out a decoding.
    Otherwise, return the contents as a string.

    :arg path: A sufficient path to the file
    :arg encoding_guess: A guess at the encoding of the file, to be applied if
        it seems to be text

    """
    # Read the binary contents of the file.
    # If mime.is_text() says it's text, try to decode it using encoding_guess.
    # If that works, return the resulting unicode.
    # Otherwise, return the binary string.
    with open(path, 'rb') as source_file:
        contents = source_file.read()  # always str
    if is_text(contents):
        try:
            contents = contents.decode(encoding_guess)
        except UnicodeDecodeError:
            pass  # Leave contents as str.
    return contents
Ejemplo n.º 4
0
def file_contents(path, encoding_guess):  # TODO: Make accessible to TreeToIndex.post_build.
    """Return the unicode contents of a file if we can figure out a decoding.
    Otherwise, return the contents as a string.

    :arg path: A sufficient path to the file
    :arg encoding_guess: A guess at the encoding of the file, to be applied if
        it seems to be text

    """
    # Read the binary contents of the file.
    # If mime.is_text() says it's text, try to decode it using encoding_guess.
    # If that works, return the resulting unicode.
    # Otherwise, return the binary string.
    with open(path, 'rb') as source_file:
        contents = source_file.read()  # always str
    if is_text(contents):
        try:
            contents = contents.decode(encoding_guess)
        except UnicodeDecodeError:
            pass  # Leave contents as str.
    return contents