def client(): application._cm = ConfigManager() application._cm.config = copy.deepcopy(conf) application.server['event'] = EventServer() application.reporter = reporter.Reporter() application.server['task'] = BackgroundTaskServer() application.encoders_decoders = EncoderDecoder() server = LyrebirdMockServer() client = server.app.test_client() yield client
def main(): """ Command line main entry Start lyrebird * start in default config ``` lyrebird ``` * start with verbose mode ``` lyrebird -v ``` * start without open a web browser ``` lyrebird -b ``` * start with a specified config file ``` lyrebird -c /path/to/your/config/file ``` * start with multipart args ``` lyrebird -v --mock 8080 -c /path/to/your/config/file ``` """ parser = argparse.ArgumentParser(prog='lyrebird') parser.add_argument('-V', '--version', dest='version', action='store_true', help='show lyrebird version') parser.add_argument('-v', dest='verbose', action='count', default=0, help='Show verbose log') parser.add_argument('--ip', dest='ip', help='Set device ip') parser.add_argument('--mock', dest='mock', type=int, help='Set mock server port, default port is 9090') parser.add_argument('--extra-mock', dest='extra_mock', type=int, help='Set extra mock server port, default port is 9999') parser.add_argument('--proxy', dest='proxy', type=int, help='Set proxy server port, default port is 4272') parser.add_argument('--data', dest='data', help='Set data dir, default is "./data/"') parser.add_argument('-b', '--no_browser', dest='no_browser', action='store_true', help='Start without open a browser') parser.add_argument('-c', '--config', dest='config', help='Start with a config file. Default is "~/.lyrebird/conf.json"') parser.add_argument('--log', dest='log', help='Set output log file path') parser.add_argument('--script', action='append', help='Set a checker script path') parser.add_argument('--plugin', action='append', help='Set a plugin project path') parser.add_argument('--database', dest='database', help='Set a database path. Default is "~/.lyrebird/lyrebird.db"') subparser = parser.add_subparsers(dest='sub_command') gen_parser = subparser.add_parser('gen') gen_parser.add_argument('path', help='Create plugin project') args = parser.parse_args() if args.version: print(version.LYREBIRD) return Path('~/.lyrebird').expanduser().mkdir(parents=True, exist_ok=True) if args.config: application._cm = ConfigManager(conf_path=args.config) else: application._cm = ConfigManager() # set current ip to config if args.ip: application._cm.config['ip'] = args.ip else: try: application._cm.config['ip'] = _get_ip() except socket.gaierror as e: logger.error(f'Failed to get local IP address, error occurs on {e}') # init file logger after config init application._cm.config['verbose'] = args.verbose log.init(args.log) if args.mock: application._cm.config['mock.port'] = args.mock if args.proxy: application._cm.config['proxy.port'] = args.proxy if args.data: application._cm.config['mock.data'] = str(Path(args.data).expanduser().absolute()) # Set extra mock port if args.extra_mock: _extra_mock_port = args.extra_mock else: _extra_mock_port = 9999 if utils.is_port_in_use(_extra_mock_port): _extra_mock_port = utils.find_free_port() application._cm.config['extra.mock.port'] = _extra_mock_port logger.debug(f'Read args: {args}') if args.sub_command == 'gen': logger.debug('EXEC: Plugin project generator') gen(args) else: logger.debug('EXEC: LYREBIRD START') run(args)
def main(): """ Command line main entry Start lyrebird * start in default config ``` lyrebird ``` * start with verbose mode ``` lyrebird -v ``` * start without open a web browser ``` lyrebird -b ``` * start with a specified config file ``` lyrebird -c /path/to/your/config/file ``` * start with multipart args ``` lyrebird -v --mock 8080 -c /path/to/your/config/file ``` """ parser = argparse.ArgumentParser(prog='lyrebird') parser.add_argument('-v', dest='verbose', action='store_true', help='Show verbose log') parser.add_argument('--mock', dest='mock', type=int, help='Set mock server port, default port is 4272') parser.add_argument('--proxy', dest='proxy', type=int, help='Set proxy server port, default port is 9090') parser.add_argument('--data', dest='data', help='Set data dir, default is "./data/"') parser.add_argument('-b', '--no_browser', dest='no_browser', action='store_true', help='Start without open a browser') parser.add_argument( '-c', '--config', dest='config', help='Start with a config file. Default is "~/.lyrebird/conf.json"') parser.add_argument('--log', dest='log', help='Set output log file path') subparser = parser.add_subparsers(dest='sub_command') src_parser = subparser.add_parser('src') src_parser.add_argument('uri') subparser.add_parser('plugin') args = parser.parse_args() if args.config: application._cm = ConfigManager(conf_path=args.config) else: application._cm = ConfigManager() application._src = Rescource() # set current ip to config try: application._cm.config['ip'] = _get_ip() except socket.gaierror as e: logger.error('Failed to get local IP address, error occurs on %s' % e) if args.verbose: application._cm.config['verbose'] = True # init file logger after config init log.init(args.log) if args.mock: application._cm.config['mock.port'] = args.mock if args.proxy: application._cm.config['proxy.port'] = args.proxy if args.data: application._cm.config['mock.data'] = args.data logger.debug(f'Read args: {args}') if args.sub_command == 'src': logger.debug('EXEC SUBCMD:SRC') src(args) elif args.sub_command == 'plugin': logger.debug('EXEC SUBCMD:PLUGIN') plugin(args) else: logger.debug('EXEC LYREBIRD START') run(args)