def app(tmpdir): with open(os.path.join(str(tmpdir), 'config.py'), 'w+') as f: contents = """# Config for testing LISTEN_HOST = '127.0.0.1' LISTEN_PORT = 5000 MONGO_HOST = '127.0.0.1' MONGO_PORT = 27017 GERRIT_URL = 'https://git.opendaylight.org/gerrit/' MIRROR_DIR = '{tmpdir}/git' """.format(tmpdir=str(tmpdir)) f.write(contents) with open(os.path.join(str(tmpdir), 'repositories.yaml'), 'w+') as f: contents = """# Repositories for testing spectrometer: repo: {tmpdir}/git """.format(tmpdir=str(tmpdir)) f.write(contents) # Clone a repo for testing clone_from = os.path.join(os.getcwd(), '..') clone_to = os.path.join(str(tmpdir), 'git', 'spectrometer.git') repo = Repo.clone_from(clone_from, clone_to) # Need to checkout a branch for the unit tests to work branch = repo.create_head('master', 'HEAD') repo.head.reference = branch config = os.path.join(str(tmpdir), 'config.py') app = create_app(config) return app
def sync(ctx): """Syncs Spectrometer data Force syncs the git repositories to pull down the latest data. """ app = create_app(ctx.obj['conf']) gerrit_url = app.config['GERRIT_URL'] mirror_dir = app.config['MIRROR_DIR'] mirror_repos(mirror_dir, gerrit_url)
def profile(ctx): from werkzeug.contrib.profiler import ProfilerMiddleware from spectrometer import create_app app = create_app(ctx.obj['conf']) app.config['PROFILE'] = True app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) app.run( debug=True, host=app.config['LISTEN_HOST'], port=app.config['LISTEN_PORT'], )
def start(ctx): """Runs the spectrometer server This function is effectively the spectrometer main() function and is the entry point for spectrometer server. """ app = create_app(ctx.obj['conf']) click.echo('Syncing Spectrometer data...') gerrit_url = app.config['GERRIT_URL'] mirror_dir = app.config['MIRROR_DIR'] mirror_repos(mirror_dir, gerrit_url) click.echo('Starting spectrometer...') app.run( threaded=True, host=app.config['LISTEN_HOST'], port=app.config['LISTEN_PORT'], )
def app(): config = os.path.join(os.getcwd(), 'config.py') app = create_app(config) return app