Example #1
0
    if request.method == "POST" and form.validate():
        article.delete(form.summary.data)
        flash("The page {} has been deleted".format(article.title))
        return render_template("article/delete_complete.html", article=article)

    return render_template("article/delete.html", article=article, form=form)


REPO_TEMPLATE = {MAIN_PAGE: "Welcome to the wiki. This is the main page.", "Help:Contents": "Do you need help?"}


if __name__ == "__main__":
    import sys

    try:
        app.repo = git.Repository(REPOSITORY_PATH)
    except KeyError:
        print("No wiki found. Creating at %r" % (REPOSITORY_PATH))
        app.repo = git.init_repository(REPOSITORY_PATH)
        author = git.Signature("Jerome Leclanche", "jerome@leclan.ch")
        builder = app.repo.TreeBuilder()
        for file, contents in REPO_TEMPLATE.items():
            builder.insert(file, app.repo.create_blob(clean_data(contents)), git.GIT_FILEMODE_BLOB)
            app.repo.create_commit("HEAD", author, WEB_COMMITTER, "Initial commit", builder.write(), [])

    ip, port = "127.0.0.1", 5000
    if len(sys.argv) > 1:
        ip = sys.argv[1]
        if len(sys.argv) > 2:
            port = int(sys.argv[2])
    app.run(ip, port)
Example #2
0
File: gasket.py Project: djs/gasket
def tree(ref):
    i = app.repo[ref]
    tree = TreeModel(app.repo, i, i.tree, None, ref)

    entries = tree

    renderer = pystache.Renderer(file_extension="html", search_dirs=["/home/dan/dev/gasket/templates"])
    loader = pystache.loader.Loader(extension="html", search_dirs=["/home/dan/dev/gasket/templates"])
    # with open('tree.html') as fh:
    #    return pystache.render(fh.read(), entries=entries)
    return renderer.render(loader.load_name("tree"), sha1=ref, entries=entries)


@app.route("/commits/<ref>/<path:filename>")
def file(ref, filename):
    commit = app.repo.revparse_single(ref)
    data = app.repo[commit.tree[filename].oid].data

    renderer = pystache.Renderer(
        file_extension="html", string_encoding="utf-8", search_dirs=["/home/dan/dev/gasket/templates"]
    )
    loader = pystache.loader.Loader(extension="html", search_dirs=["/home/dan/dev/gasket/templates"])

    return renderer.render(loader.load_name("file"), data=data)


if __name__ == "__main__":

    app.repo = pygit2.Repository("/home/dan/libgit2")
    app.debug = True
    app.run(host="0.0.0.0")