Example #1
0
def create_app(app_mode='DEBUG'):
    """ Create application, register blueprints, etc """
    # create an application
    app = Flask(__name__)
    # set logging
    if app_mode == '':
        app_mode = os.environ.get('APP_MODE', 'DEBUG')
    if app_mode == 'PROD':
        app.config.from_object(ProductionConfig)
        #create_rotating_log(app, 'app.log')
        logging.basicConfig(
            filename='app.log',
            format='%(asctime)s %(levelname)s %(message)s',
            level=logging.DEBUG)
    elif app_mode == 'OPENSHIFT':
        app.config.from_object(OpenshiftConfig)
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)s %(message)s'
        )
    else:
        #app.debug_log_format = '%(asctime)s %(levelname)s %(message)s'
        #app.logger.setLevel(logging.DEBUG)
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)s %(message)s'
        )
        app.config.from_object(Config)
    logging.debug('Starting app in %s mode' % app_mode)
    # register blueprints
    app.register_blueprint(ui)
    #register jinja2 functions
    app.jinja_env.globals.update(max=max)
    # set secret for sessions
    app.secret_key = 'Qm9enl7mikELxCbcMvsP'
    # set login manager
    app.users = dict()
    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = '/auth'
    login_manager.user_callback = user_loader
    # register flask-debugtoolbar
    if app_mode == 'DEBUG':
        app.dtb = DebugToolbarExtension(app)
    # init tinydb
    app.repo = Repository()
    app.repo.init_db(app.config['TINYDB_FILE'])
    # init WgDataProvider
    WgDataProvider.APP_ID = app.config['APP_ID']
    WgDataProvider.CACHE_DIR = app.config['CACHE_DIR']
    return app
Example #2
0
File: gasket.py Project: djs/gasket
    return renderer.render(loader.load_name('commit'), commit=commit, sha1=sha1, diff=dm)

@app.route('/trees/<ref>')
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')
Example #3
0
		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 #4
0
from flask import Flask

app = Flask(__name__)
app.config.from_object('config')

app.nodes = {}

from owner.utils import get_repo
app.repo = get_repo()

import owner.views