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 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()
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 get_bg_task(): def waitier(task_name): task = get_task(task_name) get_bg_task.__dict__['TASK'] = task if not task: raise AttributeError( f'Background Task `{task_name}` is not running.') while not task.spinned_once: sleep(1) return task yield waitier stop_tasks() while not get_bg_task.__dict__['TASK'].dead: sleep(1)
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
def background_tasks(): ''' view for background tasks customization ''' form = BackgroundTasksForms() cache_tts = data.BackgroundTask.get(name='CacheTicketsAnnouncements') delete_tickets = data.BackgroundTask.get(name='DeleteTickets') def _resolve_time(every, time): return time if every in EVERY_TIME_OPTIONS else None if form.validate_on_submit(): cache_tts.enabled = form.cache_tts_enabled.data cache_tts.every = form.cache_tts_every.data delete_tickets.enabled = form.delete_tickets_enabled.data delete_tickets.every = form.delete_tickets_every.data delete_tickets.time = _resolve_time(delete_tickets.every, form.delete_tickets_time.data) db.session.commit() stop_tasks() start_tasks() flash('Notice: background tasks got updated successfully.', 'info') return redirect(url_for('cust_app.background_tasks')) if not form.errors: form.cache_tts_enabled.data = cache_tts.enabled form.cache_tts_every.data = cache_tts.every form.delete_tickets_enabled.data = delete_tickets.enabled form.delete_tickets_every.data = delete_tickets.every form.delete_tickets_time.data = delete_tickets.time return render_template('background_tasks.html', page_title='Background Tasks', navbar='#snb2', form=form, hash='#da9', vtrue=data.Vid.get().enable, strue=data.Slides_c.get().status, time_options=','.join(EVERY_TIME_OPTIONS))
def interface(cli, quiet, reset, 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 = 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 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() elif reset: with app.app_context(): User.reset_default_password() click.echo('Admmin password was reset.') 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() stop_tasks()
def exiting(): stop_tasks() sys.exit(0)