Пример #1
0
def view(request, repo_name, branch, commit_sha=None):
    """
    view diffs of affeted files in the commit
    """
    commit = diff = None
    repo = get_repo( repo_name )
    commit_list = get_commit( repo, commit_sha)
    if commit_list:
        commit = commit_list[0]
        if len(commit_list) > 1:
            diff = get_diff( repo, commit_list[1].hexsha, commit.hexsha, )

    context = dict(
        STRATUS_MEDIA_URL = STRATUS_MEDIA_URL,
        repo_name = repo_name,
        branch_name = branch,
        repo = repo,
        diff = diff,
        commit = commit,
    )

    return mix_response( 
        request, 
        'stratus/commit.html', 
        context)
Пример #2
0
def view(request, repo_name, branch, commit_sha=None):
    """
    view diffs of affeted files in the commit
    """
    commit = diff = None
    repo = get_repo( repo_name )
    commit_list = get_commit( repo, commit_sha)
    if commit_list:
        commit = commit_list[0]
        diff = get_diff( repo, commit_list[1].hexsha, commit.hexsha,  )

    context = dict(
        GITTER_MEDIA_URL = GITTER_MEDIA_URL,
        repo_name = repo_name,
        branch_name = branch,
        diff = diff,
        commit = commit,
    )

    return mix_response( 
        request, 
        'commitlog/commit.html', 
        context)
Пример #3
0
def view(request, repo_name, branch, path, commit_sha=None):
    """
    view file in the commit
    """
    file_source = diff = ""

    if path in FILE_BLACK_LIST:
        msg = MSG_NOT_ALLOWED
        return error_view(request, msg)

    file_path = path  #!!! FIX security
    if path[-1:] == "/":
        path = path[:-1]

    repo = get_repo(repo_name)
    commit, tree = get_commit_tree(repo, commit_sha)

    if commit.parents:
        diff = get_diff(repo, path, commit.parents[0].hexsha, commit.hexsha)

    try:
        tree = tree[path]
    except KeyError:
        msg = MSG_NO_FILE_IN_TREE
        return error_view(request, msg)

    if not tree.type is "blob":
        msg = MSG_NO_FILE_IN_TREE
        return error_view(request, msg)

    mime = tree.mime_type.split("/")

    file_source = tree.data_stream[3].read()

    # import ipdb; ipdb.set_trace()
    file_meta = dict(
        STRATUS_MEDIA_URL=STRATUS_MEDIA_URL,
        abspath=tree.abspath,
        mime=tree.mime_type,
        size=tree.size,
        tree=tree,
        path=tree.abspath,
        mime_type=mime[0],
        type=file_type_from_mime(tree.mime_type),
    )
    context = dict(
        STRATUS_MEDIA_URL=STRATUS_MEDIA_URL,
        file_source=file_source,
        breadcrumbs=make_crumbs(path),
        commit=commit,
        diff=diff,
        file_meta=file_meta,
        repo_name=repo_name,
        repo=repo,
        branch_name=branch,
        path=path,
        name=path.split("/")[-1:][0],
    )
    if mime[0] == "image":
        import base64

        context["img_base"] = base64.b64encode(file_source)
        from getimageinfo import getImageInfo

        context["img_meta"] = getImageInfo(file_source)

    return mix_response(request, "stratus/view_file.html", context)