コード例 #1
0
ファイル: views.py プロジェクト: degenhard/brigitte
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == '/':
        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(request, 'repositories/repository_tree.html', {
            'repository': repo,
            'commit': commit,
            'tree': tree,
            'breadcrumb': build_path_breadcrumb(path)
        })

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(
            path.rsplit('.', 1)[-1], file_obj.content)

        return render(request, 'repositories/repository_file.html', {
            'repository': repo,
            'commit': commit,
            'file_path': path,
            'file_obj': file_obj,
            'file_lines': range(1, file_obj.content.count('\n') + 1),
            'file_blob_pygmentized': file_blob_pygmentized,
            'breadcrumb': build_path_breadcrumb(path)
        })
コード例 #2
0
ファイル: views.py プロジェクト: EnTeQuAk/brigitte
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == "/":
        if request.is_ajax() and "commits" in request.GET:
            tree = commit.get_tree(path, commits=True).tree
            tree_elements = []
            for entry in tree:
                tree_elements.append(
                    {
                        "tree_id": entry["sha"],
                        "id": entry["commit"].id,
                        "author": entry["commit"].author,
                        "commit_date": entry["commit"].commit_date,
                        "since": timesince(entry["commit"].commit_date),
                    }
                )
            return HttpResponse(simplejson.dumps(tree_elements, cls=DjangoJSONEncoder), mimetype="application/json")

        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(
            request,
            "repositories/repository_tree.html",
            {"repository": repo, "commit": commit, "tree": tree, "breadcrumb": build_path_breadcrumb(path)},
        )

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(path.rsplit(".", 1)[-1], file_obj.content)

        return render(
            request,
            "repositories/repository_file.html",
            {
                "repository": repo,
                "commit": commit,
                "file_path": path,
                "file_obj": file_obj,
                "file_lines": range(1, file_obj.content.count("\n") + 1),
                "file_blob_pygmentized": file_blob_pygmentized,
                "breadcrumb": build_path_breadcrumb(path),
            },
        )
コード例 #3
0
ファイル: views.py プロジェクト: MasterofJOKers/brigitte
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == '/':
        if request.is_ajax() and 'commits' in request.GET:
            tree = commit.get_tree(path, commits=True).tree
            tree_elements = []
            for entry in tree:
                tree_elements.append({
                    'tree_id': entry['sha'],
                    'id': entry['commit'].id,
                    'author': entry['commit'].author,
                    'commit_date': entry['commit'].commit_date,
                    'since': timesince(entry['commit'].commit_date),
                })
            return HttpResponse(simplejson.dumps(tree_elements,
                cls=DjangoJSONEncoder), mimetype='application/json')

        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(request, 'repositories/repository_tree.html', {
            'repository': repo,
            'commit': commit,
            'tree': tree,
            'breadcrumb': build_path_breadcrumb(path)
        })

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(
            path.rsplit('.', 1)[-1], file_obj.content)

        return render(request, 'repositories/repository_file.html', {
            'repository': repo,
            'commit': commit,
            'file_path': path,
            'file_obj': file_obj,
            'file_lines': range(1, file_obj.content.count('\n') + 1),
            'file_blob_pygmentized': file_blob_pygmentized,
            'breadcrumb': build_path_breadcrumb(path)
        })
コード例 #4
0
ファイル: views.py プロジェクト: stefanw/brigitte
def repositories_commit_tree(request, repo, sha, path=None):
    commit = repo.get_commit(sha)

    if not commit:
        raise Http404

    if not path or path[-1] == '/':
        if request.is_ajax() and 'commits' in request.GET:
            tree = commit.get_tree(path, commits=True).tree
            tree_elements = []
            for entry in tree:
                tree_elements.append({
                    'tree_id': entry['sha'],
                    'id': entry['commit'].id,
                    'author': entry['commit'].author,
                    'commit_date': entry['commit'].commit_date,
                    'since': timesince(entry['commit'].commit_date),
                })
            return HttpResponse(simplejson.dumps(tree_elements,
                cls=DjangoJSONEncoder), mimetype='application/json')

        tree = commit.get_tree(path)
        if tree is None:
            raise Http404

        return render(request, 'repositories/repository_tree.html', {
            'repository': repo,
            'commit': commit,
            'tree': tree,
            'breadcrumb': build_path_breadcrumb(path)
        })

    else:
        file_obj = commit.get_file(path)
        if file_obj is None:
            raise Http404

        file_blob_pygmentized = pygmentize(
            path.rsplit('.', 1)[-1], file_obj.content)

        return render(request, 'repositories/repository_file.html', {
            'repository': repo,
            'commit': commit,
            'file_path': path,
            'file_obj': file_obj,
            'file_lines': range(1, file_obj.content.count('\n') + 1),
            'file_blob_pygmentized': file_blob_pygmentized,
            'breadcrumb': build_path_breadcrumb(path)
        })
コード例 #5
0
def pygmentize_diff(blob):
    try:
        return pygmentize('diff', blob)
    except:
        return blob
コード例 #6
0
def pygmentize_diff(blob):
    try:
        return pygmentize('diff', blob)
    except:
        return blob