def setUp(self): db._db = None db.coll.cache_clear() db.fs.cache_clear() options.db_name = 'unittest_' + str(os.getpid()) wait(db.init()) wait(tools.ensure_all_indexes())
def __init__(self): super(Application, self).__init__(debug=options.debug) globals()[self.__class__.__name__] = lambda: self # singleton static_path = path.join(path.dirname(__file__), '.uibuild') translation_path = path.join(path.dirname(__file__), 'locale') # Initialize components. staticmanifest.init(static_path) locale.load_translations(translation_path) loop = asyncio.get_event_loop() loop.run_until_complete(db.init()) loop.run_until_complete(system.setup()) loop.run_until_complete(system.ensure_db_version()) loop.run_until_complete(asyncio.gather(tools.ensure_all_indexes(), bus.init())) smallcache.init() # Load views. from vj4.handler import contest from vj4.handler import discussion from vj4.handler import domain from vj4.handler import fs from vj4.handler import home from vj4.handler import judge from vj4.handler import misc from vj4.handler import problem from vj4.handler import record from vj4.handler import training from vj4.handler import user from vj4.handler import i18n if options.static: self.router.add_static('/', static_path, name='static')
def setUp(self): db._client = None db._db = None db.coll.cache_clear() db.fs.cache_clear() options.db_name = 'unittest_' + str(os.getpid()) wait(db.init()) wait(tools.ensure_all_indexes())
def invoke_by_args(): import argparse import asyncio import coloredlogs import inspect import pprint coloredlogs.install( fmt='[%(levelname).1s %(asctime)s %(module)s:%(lineno)d] %(message)s', datefmt='%y%m%d %H:%M:%S') parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='') for name, method in _methods.items(): subparser = subparsers.add_parser(name) argcount = method.__code__.co_argcount num_defaults = len(method.__defaults__) if method.__defaults__ else 0 argoffset = argcount - num_defaults for index, argname in enumerate( method.__code__.co_varnames[:argcount]): if index < argoffset: subparser.add_argument(argname, type=method.__annotations__[argname]) elif argname in method.__annotations__: subparser.add_argument(argname, type=method.__annotations__[argname], nargs='?', default=method.__defaults__[index - argoffset]) args = parser.parse_args(options.leftovers) name = getattr(args, '') delattr(args, '') if not name: parser.print_help() else: loop = asyncio.get_event_loop() loop.run_until_complete(db.init()) try: result = _methods[name](**vars(args)) if inspect.iscoroutine(result): result = loop.run_until_complete(result) if options.pretty: print_func = pprint.pprint else: print_func = lambda x: print(x) if x is not None else None if hasattr(result, '__aiter__'): async def aloop(): async for entry in result: print_func(entry) loop.run_until_complete(aloop()) else: print_func(result) except KeyboardInterrupt: pass finally: loop.set_exception_handler(lambda loop, context: None)
def invoke_by_args(): import argparse import asyncio import coloredlogs import inspect import pprint coloredlogs.install(fmt='[%(levelname).1s %(asctime)s %(module)s:%(lineno)d] %(message)s', datefmt='%y%m%d %H:%M:%S') parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='') for name, method in _methods.items(): subparser = subparsers.add_parser(name) argcount = method.__code__.co_argcount num_defaults = len(method.__defaults__) if method.__defaults__ else 0 argoffset = argcount - num_defaults for index, argname in enumerate(method.__code__.co_varnames[:argcount]): if index < argoffset: subparser.add_argument(argname, type=method.__annotations__[argname]) elif argname in method.__annotations__: subparser.add_argument(argname, type=method.__annotations__[argname], nargs='?', default=method.__defaults__[index - argoffset]) args = parser.parse_args(options.leftovers) name = getattr(args, '') delattr(args, '') if not name: parser.print_help() else: loop = asyncio.get_event_loop() loop.run_until_complete(db.init()) try: result = _methods[name](**vars(args)) if inspect.iscoroutine(result): result = loop.run_until_complete(result) if options.pretty: print_func = pprint.pprint else: print_func = lambda x: print(x) if x is not None else None if hasattr(result, '__aiter__'): async def aloop(): async for entry in result: print_func(entry) loop.run_until_complete(aloop()) else: print_func(result) except KeyboardInterrupt: pass finally: loop.set_exception_handler(lambda loop, context: None)
def __init__(self): middlewares = [] if options.sentry_dsn: middlewares.append( SentryMiddleware({ 'dsn': options.sentry_dsn, 'environment': 'vj4', 'debug': options.debug, })) super(Application, self).__init__(debug=options.debug, middlewares=middlewares, client_max_size=10 * 1024**2) globals()[self.__class__.__name__] = lambda: self # singleton static_path = path.join(path.dirname(__file__), '.uibuild') # Initialize components. staticmanifest.init(static_path) loop = asyncio.get_event_loop() loop.run_until_complete(db.init()) loop.run_until_complete(system.setup()) loop.run_until_complete(system.ensure_db_version()) loop.run_until_complete( asyncio.gather(tools.ensure_all_indexes(), bus.init())) smallcache.init() # Load views. from vj4.handler import contest from vj4.handler import discussion from vj4.handler import domain from vj4.handler import fs from vj4.handler import home from vj4.handler import homework from vj4.handler import judge from vj4.handler import misc from vj4.handler import problem from vj4.handler import record from vj4.handler import training from vj4.handler import ranking from vj4.handler import user from vj4.handler import i18n from vj4.handler import report if options.static: self.router.add_static('/', static_path, name='static')
def invoke_by_args(): logging.config.dictConfig({ 'version': 1, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'formatter': 'colored', }, }, 'formatters': { 'colored': { '()': 'colorlog.ColoredFormatter', 'format': '%(log_color)s[%(levelname).1s ' '%(asctime)s %(module)s:%(lineno)d]%(reset)s %(message)s', 'datefmt': '%y%m%d %H:%M:%S' } }, 'root': { 'level': 'INFO', 'handlers': ['console'], }, 'disable_existing_loggers': False, }) import argparse import asyncio import inspect import pprint parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='') for name, method in _methods.items(): subparser = subparsers.add_parser(name) argcount = method.__code__.co_argcount num_defaults = len(method.__defaults__) if method.__defaults__ else 0 argoffset = argcount - num_defaults for index, argname in enumerate(method.__code__.co_varnames[:argcount]): if index < argoffset: subparser.add_argument(argname, type=method.__annotations__[argname]) elif argname in method.__annotations__: subparser.add_argument(argname, type=method.__annotations__[argname], nargs='?', default=method.__defaults__[index - argoffset]) args = parser.parse_args(options.leftovers) name = getattr(args, '') delattr(args, '') if not name: parser.print_help() else: loop = asyncio.get_event_loop() loop.run_until_complete(db.init()) try: result = _methods[name](**vars(args)) if inspect.iscoroutine(result): result = loop.run_until_complete(result) if options.pretty: print_func = pprint.pprint else: print_func = lambda x: print(x) if x is not None else None if hasattr(result, '__aiter__'): async def aloop(): async for entry in result: print_func(entry) loop.run_until_complete(aloop()) else: print_func(result) except KeyboardInterrupt: pass finally: loop.set_exception_handler(lambda loop, context: None)