def c(): app_config = { 'LOGIN_DISABLED': True, 'WTF_CSRF_ENABLED': False, 'TESTING': True, 'SQLALCHEMY_DATABASE_URI': f'sqlite:///{DB_PATH}' } db_fd, app_config['DATABASE'] = tempfile.mkstemp() app = bundle_app(app_config) # FIXME: Tasks are not integration tested yet. stop_tasks() with app.test_client() as client: with app.app_context(): db.create_all() teardown_tables(copy.copy(MODULES)) fill_offices() fill_tasks() fill_users() fill_tickets() yield client register(lambda: os.path.isfile(DB_PATH) and os.remove(DB_PATH)) os.close(db_fd) os.unlink(app.config['DATABASE'])
def c(): app_config = { 'LOGIN_DISABLED': True, 'WTF_CSRF_ENABLED': False, 'TESTING': True, 'DB_NAME': DB_NAME, 'SQLALCHEMY_DATABASE_URI': f'sqlite:///{DB_PATH}' } db_fd, app_config['DATABASE'] = tempfile.mkstemp() app = bundle_app(app_config) # FIXME: Tasks are not integration tested yet. stop_tasks() with app.test_client() as client: with app.app_context(): db.create_all() teardown_tables(copy.copy(MODULES)) recreate_defaults(DEFAULT_MODULES) fill_offices() fill_tasks() fill_users() fill_tickets() fill_slides() yield client os.close(db_fd) os.unlink(app.config['DATABASE']) before_exit()
def interface(cli, quiet, ip, port): app = bundle_app() if cli: ip = ip or get_accessible_ips()[0][1] port = port or get_random_available_port(ip) app.config['LOCALADDR'] = ip click.echo( click.style(f'FQM {VERSION} is running on http://{ip}:{port}', bold=True, fg='green')) click.echo('') click.echo( click.style('Press Control-c to stop', blink=True, fg='black', bg='white')) monkey.patch_socket() pywsgi.WSGIServer( (str(ip), int(port)), app, log=None if quiet else 'default').serve_forever() else: gui_process = QApplication(sys.argv) window = MainWindow( app) # NOTE: has to be decleared in a var to work properly QCoreApplication.processEvents() gui_process.exec_()
def interface(cli, quiet, ip, port): ''' FQM command-line interface (CLI): * if `--cli` is not used, initializing GUI will be attempted.\n * If no `ip` is passed it will default to `127.0.0.1`.\n * If no `port` is passed it will default to a random port.\n ''' app = bundle_app() def start_cli(): alt_ip = '192.168.178.84' or get_accessible_ips()[0][1] alt_port = port or get_random_available_port(alt_ip) app.config['LOCALADDR'] = alt_ip app.config['CLI_OR_DEPLOY'] = True app.config['QUIET'] = quiet click.echo( click.style( f'FQM {VERSION} is running on http://{alt_ip}:{alt_port}', bold=True, fg='green')) click.echo('') click.echo( click.style('Press Control-c to stop', blink=True, fg='black', bg='white')) try: monkey.patch_socket() pywsgi.WSGIServer( (str(alt_ip), int(alt_port)), app, log=None if quiet else 'default').serve_forever() except KeyboardInterrupt: stop_tasks() if cli: start_cli() else: try: app.config['CLI_OR_DEPLOY'] = False gui_process = import_module('PyQt5.QtWidgets').QApplication( sys.argv) window = import_module('app.gui').MainWindow( app) # NOTE: has to be decleared in a var to work properly import_module('PyQt5.QtCore').QCoreApplication.processEvents() gui_process.exec_() except Exception as e: if not quiet: print('Failed to start PyQt GUI, fallback to CLI.') log_error(e, quiet=quiet) start_cli()
def run_app(): ''' To run the app through a command-line interface. ''' app = bundle_app() @click.command() @click.option('--cli', is_flag=True, default=False, help='To use commandline interface instead of GUI.') @click.option('--quiet', is_flag=True, default=False, help='To silence web server logs.') @click.option('--ip', default=None, help='IP address to stream the service on.') @click.option('--port', default=None, help='Port to stream the service through.') def interface(cli, quiet, ip, port): if cli: ip = ip or get_accessible_ips()[0][1] port = port or get_random_available_port(ip) app.config['LOCALADDR'] = ip click.echo( click.style(f'FQM {VERSION} is running on http://{ip}:{port}', bold=True, fg='green')) click.echo('') click.echo( click.style('Press Control-c to stop', blink=True, fg='black', bg='white')) monkey.patch_socket() pywsgi.WSGIServer( (str(ip), int(port)), app, log=None if quiet else 'default').serve_forever() else: gui_process = QApplication(sys.argv) window = MainWindow( app) # NOTE: has to be decleared in a var to work properly QCoreApplication.processEvents() gui_process.exec_() interface()
def interface(cli, quiet, ip, port): app = bundle_app() def start_cli(): alt_ip = ip or get_accessible_ips()[0][1] alt_port = port or get_random_available_port(alt_ip) app.config['LOCALADDR'] = alt_ip app.config['CLI_OR_DEPLOY'] = True click.echo( click.style( f'FQM {VERSION} is running on http://{alt_ip}:{alt_port}', bold=True, fg='green')) click.echo('') click.echo( click.style('Press Control-c to stop', blink=True, fg='black', bg='white')) monkey.patch_socket() try: pywsgi.WSGIServer( (str(alt_ip), int(alt_port)), app, log=None if quiet else 'default').serve_forever() except KeyboardInterrupt: stop_tasks() if cli: start_cli() else: try: app.config['CLI_OR_DEPLOY'] = False gui_process = import_module('PyQt5.QtWidgets').QApplication( sys.argv) window = import_module('app.gui').MainWindow( app) # NOTE: has to be decleared in a var to work properly import_module('PyQt5.QtCore').QCoreApplication.processEvents() gui_process.exec_() except Exception as e: print('Failed to start PyQt GUI, fallback to CLI.') print(e) start_cli()
def client(): app = bundle_app({'LOGIN_DISABLED': True, 'WTF_CSRF_ENABLED': False}) db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_PATH}' with app.test_client() as client: with app.app_context(): create_db(app) teardown_tables(copy.copy(MODULES)) fill_offices() fill_tasks() fill_users() yield client register(lambda: os.path.isfile(DB_PATH) and os.remove(DB_PATH)) os.close(db_fd) os.unlink(app.config['DATABASE'])
def c(): app_config = {'LOGIN_DISABLED': True, 'WTF_CSRF_ENABLED': False, 'TESTING': True, 'DB_NAME': DB_NAME, 'SQLALCHEMY_DATABASE_URI': f'sqlite:///{DB_PATH}?check_same_thread=False'} app = bundle_app(app_config) stop_tasks() with app.test_client() as client: with app.app_context(): db.create_all() teardown_tables(copy.copy(MODULES)) recreate_defaults(DEFAULT_MODULES) fill_offices() fill_tasks() fill_users() fill_tickets() fill_slides() fill_tokens() yield client
import os from app.main import bundle_app # noqa # NOTE: uncomment out while genrating migration # app = bundle_app({'MIGRATION': True}) application = bundle_app({ 'CLI_OR_DEPLOY': True, 'GUNICORN': 'gunicorn' in os.environ.get('SERVER_SOFTWARE', '')}) # noqa