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
return ipfsapi.connect(*args, **kwargs) except: return None app.ipfs = ipfs_try_conn() while app.ipfs == None: # If the first connection fails, assume we're running in docker and wait # for the service to come up. print('Waiting on IPFS node to be available...') time.sleep(1) print('Trying to connect') app.ipfs = ipfs_try_conn('ipfs') if app.config.get('METAREPO_URL'): app.repo = repomgmt.clone_temp(app.config['METAREPO_URL']) app.meta_rev = app.repo.current_rev_str() elif app.config.get('LOCAL_METAREPO_PATH'): from repomgmt import MetaRepo print('Running with local repository') app.repo = None app.meta_rev = MetaRepo( app.config.get('LOCAL_METAREPO_PATH')).current_rev_str() else: print( 'Error: no metarepo specified. Set METAREPO_URL or LOCAL_METAREPO_PATH' ) exit() def file_pinned(hash_, info):
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", "*****@*****.**") 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)
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')
try: return ipfsapi.connect(*args, **kwargs) except: return None app.ipfs = ipfs_try_conn() while app.ipfs == None: # If the first connection fails, assume we're running in docker and wait # for the service to come up. print('Waiting on IPFS node to be available...') time.sleep(1) print('Trying to connect') app.ipfs = ipfs_try_conn('ipfs') app.repo = repomgmt.clone_temp(repo_url) app.meta_rev = app.repo.current_rev_str() def file_pinned(hash_): """ Callback executed when a file is pinned. """ app.pins.add(hash_) def pin_files_async(): """ Pins files to IPFS in another thread """ def func():
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