Beispiel #1
0
def title(context, obj):
    ctx = context['context']

    if isinstance(obj, BlobObject):
        doc = render_blob(ctx, obj)
        return doc.title

    elif isinstance(obj, TreeObject):
        readme_obj = utils.find_readme(obj)
        if readme_obj is not None:
            readme_doc = render_blob(ctx, readme_obj)
            return readme_doc.title

    else:
        # TODO: LinkObject
        pass
Beispiel #2
0
def tree(ctx, rev, path):
    if rev == "HEAD":
        commit_obj = ctx.odb.head
    elif rev == "index":
        commit_obj = ctx.odb.index
        if commit_obj is None:
            raise NotFound("No such file or directory")
    else:
        commit_obj = ctx.odb.get_commit(rev)

    try:
        tree_obj = commit_obj.tree[path]

    except KeyError:
        raise NotFound("No such file or directory")

    if not isinstance(tree_obj, TreeObject):
        raise NotFound("No such file or directory")

    readme_obj = utils.find_readme(tree_obj)
    if readme_obj is not None:
        readme_doc = render_blob(ctx, readme_obj)
        readme = ctx.render_template("readme.html", doc=readme_doc)

    else:
        readme = None

    return ctx.render_to_response("tree.html", commit=commit_obj, tree=tree_obj, readme=readme)
Beispiel #3
0
def atom(ctx):
    feed = AtomFeed(ctx.odb.name, feed_url=ctx.url_for("atom"), url=ctx.url_for("root"), subtitle=ctx.odb.description)

    pattern = ctx.app.recent_doc_pattern

    for added_date, root_path in utils.recent_files(ctx, count=10, pattern=pattern):
        blob_obj = ctx.odb.head.tree[root_path]
        assert isinstance(blob_obj, BlobObject)

        current_blob_obj = ctx.odb.head.tree[blob_obj.abs_name]

        doc = render_blob(ctx, current_blob_obj)
        url = "http://" + ctx.request.host + ctx.url_for("view_obj", rev="HEAD", path=blob_obj.root_path)
        feed.add(
            doc.title,
            doc.body,
            title_type="html",
            content_type="html",
            author=doc.author_name,
            url=url,
            updated=doc.last_modified,
            published=added_date,
        )

    return feed.get_response()
Beispiel #4
0
def blob(ctx, rev, path):
    if rev == "HEAD":
        commit_obj = ctx.odb.head
    elif rev == "index":
        commit_obj = ctx.odb.index
        if commit_obj is None:
            raise NotFound("No such file or directory")
    else:
        commit_obj = ctx.odb.get_commit(rev)

    try:
        blob_obj = commit_obj.tree[path]

    except KeyError:
        raise NotFound("No such file or directory")

    if isinstance(blob_obj, TreeObject):
        # redirect to same URL with trailing "/"
        return redirect(ctx.url_for("view_obj", rev=rev, path=path + "/"))
    elif isinstance(blob_obj, LinkObject):
        raise NotFound("No such file or directory")

    if "raw" in ctx.request.args:
        content_type, encoding = mimetypes.guess_type(blob_obj.name)

        if content_type is None:
            if "\x00" in blob_obj.data:
                content_type = "application/octat-stream"
            else:
                content_type = "text/plain"

        # TODO: use encoding
        response = Response(blob_obj.data, content_type=content_type)
        response.headers["X-Robots-Tag"] = "noindex"
    else:
        doc = render_blob(ctx, blob_obj)

        response = ctx.render_to_response("blob.html", doc=doc, blob=blob_obj, commit=commit_obj)

    return response
Beispiel #5
0
def document(context, obj):
    ctx = context['context']
    return render_blob(ctx, obj)