Ejemplo n.º 1
0
def run(args: argparse.Namespace):
    # show current config contents
    config_str = json.dumps(application._cm.config,
                            ensure_ascii=False,
                            indent=4)
    logger.warning(f'Lyrebird start with config:\n{config_str}')

    application.server['event'] = EventServer()
    application.server['task'] = BackgroundTaskServer()
    application.server['proxy'] = LyrebirdProxyServer()
    application.server['mock'] = LyrebirdMockServer()

    application.start_server()

    # auto open web browser
    if not args.no_browser:
        webbrowser.open(f'http://localhost:{application.config["mock.port"]}')

    # stop event handler
    def signal_handler(signum, frame):
        application.stop_server()
        threading.Event().set()
        logger.warning('!!!Ctrl-C pressed. Lyrebird stop!!!')
        os._exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
Ejemplo n.º 2
0
def run(args:argparse.Namespace):
    # Check mock data group version. Update if is older than 1.x
    from . import mock_data_formater
    data_path = application._cm.config['mock.data']
    data_dir = Path(data_path)
    mock_data_formater.check_data_dir(data_dir)

    # show current config contents
    config_str = json.dumps(application._cm.config, ensure_ascii=False, indent=4)
    logger.warning(f'Lyrebird start with config:\n{config_str}')

    application.server['event'] = EventServer()
    application.server['task'] = BackgroundTaskServer()
    application.server['proxy'] = LyrebirdProxyServer()   
    application.server['mock'] = LyrebirdMockServer()

    application.start_server()

    # activate notice center
    application.notice = NoticeCenter()
    
    # auto open web browser
    if not args.no_browser:
        webbrowser.open(f'http://localhost:{application.config["mock.port"]}')

    # stop event handler
    def signal_handler(signum, frame):
        application.stop_server()
        threading.Event().set()
        logger.warning('!!!Ctrl-C pressed. Lyrebird stop!!!')
        os._exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
Ejemplo n.º 3
0
def run(args: argparse.Namespace):
    # Check mock data group version. Update if is older than 1.x
    from . import mock_data_formater
    data_path = application._cm.config['mock.data']
    data_dir = Path(data_path)
    mock_data_formater.check_data_dir(data_dir)

    # show current config contents
    config_str = json.dumps(application._cm.config, ensure_ascii=False, indent=4)
    logger.warning(f'Lyrebird start with config:\n{config_str}')

    # Main server
    application.server['event'] = EventServer()

    application.server['task'] = BackgroundTaskServer()
    application.server['proxy'] = LyrebirdProxyServer()
    application.server['mock'] = LyrebirdMockServer()
    application.server['db'] = LyrebirdDatabaseServer()
    application.server['plugin'] = PluginManager()
    application.server['checker'] = LyrebirdCheckerServer()

    application.start_server()

    # int statistics reporter
    application.reporter = reporter.Reporter()
    reporter.start()
    # activate notice center
    application.notice = NoticeCenter()

    # load debug plugin
    # TODO
    plugin_manager = application.server['plugin']
    if args.plugin:
        plugin_manager.plugin_path_list += args.plugin
    plugin_manager.reload()

    # load debug script
    if args.script:
        application.server['checker'].load_scripts(args.script)

    # auto open web browser
    if not args.no_browser:
        webbrowser.open(f'http://localhost:{application.config["mock.port"]}')

    # stop event handler
    def signal_handler(signum, frame):
        reporter.stop()
        application.stop_server()
        threading.Event().set()
        logger.warning('!!!Ctrl-C pressed. Lyrebird stop!!!')
        os._exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    threading.Event().wait()
Ejemplo n.º 4
0
    def start(self):
        """
        启动proxy&mock

        """
        init_logger_settings(verbose=self.verbose)
        self.init_conf()
        
        application.server['event'] = EventServer()
        application.server['task'] = BackgroundTaskServer()
        application.server['proxy'] = LyrebirdProxyServer()   
        application.server['mock'] = LyrebirdMockServer()

        application.start_server()
Ejemplo n.º 5
0
def run(args: argparse.Namespace):
    sys_name = platform.system()
    if sys_name.lower() != 'windows':
        import resource

        # Set file descriptors
        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (8192, 8192))
        except Exception:
            traceback.print_exc()
            logger.warning('Set file descriptors failed\nPlease set it by your self, use "ulimit -n 8192" with root account')

    # show current config contents
    print_lyrebird_info()
    config_str = json.dumps(application._cm.config, ensure_ascii=False, indent=4)
    logger.warning(f'Lyrebird start with config:\n{config_str}')

    # Main server
    application.server['event'] = EventServer()

    application.server['task'] = BackgroundTaskServer()
    application.server['proxy'] = LyrebirdProxyServer()
    application.server['mock'] = LyrebirdMockServer()
    application.server['extra.mock'] = ExtraMockServer()
    application.server['db'] = LyrebirdDatabaseServer(path=args.database)
    application.server['plugin'] = PluginManager()
    application.server['checker'] = LyrebirdCheckerServer()

    application.start_server()

    # int statistics reporter
    application.reporter = reporter.Reporter()
    reporter.start()
    # activate notice center
    application.notice = NoticeCenter()

    # init label handler
    application.labels = LabelHandler()

    # init encoder&decoder
    application.encoders_decoders = EncoderDecoder()

    # load debug plugin
    # TODO
    plugin_manager = application.server['plugin']
    if args.plugin:
        plugin_manager.plugin_path_list += args.plugin
    plugin_manager.reload()

    # load debug script
    if args.script:
        application.server['checker'].load_scripts(args.script)

    # auto open web browser
    if not args.no_browser:
        webbrowser.open(f'http://localhost:{application.config["mock.port"]}')

    # Lyrebird status contains: 'READY' and 'INITING'
    application.status = 'READY'

    # stop event handler
    def signal_handler(signum, frame):
        reporter.stop()
        application.stop_server()
        threading.Event().set()
        logger.warning('!!!Ctrl-C pressed. Lyrebird stop!!!')
        os._exit(0)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    threading.Event().wait()
Ejemplo n.º 6
0
def run(args: argparse.Namespace):
    sys_name = platform.system()
    if sys_name.lower() != 'windows':
        import resource
        # Set file descriptors
        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (8192, 8192))
        except Exception:
            traceback.print_exc()
            logger.warning(
                'Set file descriptors failed\nPlease set it by your self, use "ulimit -n 8192" with root account'
            )
    # Check mock data group version. Update if is older than 1.x
    data_path = application._cm.config['mock.data']
    Path(data_path).mkdir(parents=True, exist_ok=True)
    res = mock_data_tools.check_data_version(data_path)
    mockdata_version = vparse(res)

    if MOCK_DATA_V_1_0_0 <= mockdata_version < MOCK_DATA_V_1_7_0:
        logger.log(60, 'Mock data need update')
        mock_data_tools.update(data_path)
    elif mockdata_version < MOCK_DATA_V_1_0_0:
        logger.error('Can not update this mock data')

    # show current config contents
    print_lyrebird_info()
    config_str = json.dumps(application._cm.config,
                            ensure_ascii=False,
                            indent=4)
    logger.warning(f'Lyrebird start with config:\n{config_str}')

    # Main server
    application.server['event'] = EventServer()

    application.server['task'] = BackgroundTaskServer()
    application.server['proxy'] = LyrebirdProxyServer()
    application.server['mock'] = LyrebirdMockServer()
    application.server['db'] = LyrebirdDatabaseServer(path=args.database)
    application.server['plugin'] = PluginManager()
    application.server['checker'] = LyrebirdCheckerServer()

    application.start_server()

    # int statistics reporter
    application.reporter = reporter.Reporter()
    reporter.start()
    # activate notice center
    application.notice = NoticeCenter()

    # init label handler
    application.labels = LabelHandler()

    # load debug plugin
    # TODO
    plugin_manager = application.server['plugin']
    if args.plugin:
        plugin_manager.plugin_path_list += args.plugin
    plugin_manager.reload()

    # load debug script
    if args.script:
        application.server['checker'].load_scripts(args.script)

    # auto open web browser
    if not args.no_browser:
        webbrowser.open(f'http://localhost:{application.config["mock.port"]}')

    # stop event handler
    def signal_handler(signum, frame):
        reporter.stop()
        application.stop_server()
        threading.Event().set()
        logger.warning('!!!Ctrl-C pressed. Lyrebird stop!!!')
        os._exit(1)

    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)

    threading.Event().wait()