예제 #1
0
def logExceptions(msg="Exception occured", logger=None, basetype=Exception):
    """Creates a try/catch block that logs exceptions"""
    try:
        yield
    except basetype:
        if not logger:
            logger = logging.getLogger(classtools.get_calling_module())
        logger.exception(msg)
예제 #2
0
def logExceptions(msg="Exception occured", logger=None, basetype=Exception):
    """Creates a try/catch block that logs exceptions"""
    try:
        yield
    except basetype:
        if not logger:
            logger = logging.getLogger(classtools.get_calling_module())
        logger.exception(msg)
예제 #3
0
파일: cli.py 프로젝트: BBie/amcat
def run_cli(cls=None):
    """Handle command line interface invocation of this script"""

    if cls is None:
        module = classtools.get_calling_module()
        cls = classtools.get_class_from_module(module, Script)

    parser = argument_parser_from_script(cls)
    args = parser.parse_args()
    options = args.__dict__

    verbose = options.pop("verbose", None)
    logging.basicConfig(format='[%(asctime)s] [%(name)s] %(message)s',
                        level=(logging.DEBUG if verbose else logging.INFO))
    logging.getLogger('requests').setLevel(logging.WARN)

    instance = cls(options)

    return instance.run()
예제 #4
0
def run_cli(cls=None):
    """Handle command line interface invocation of this script"""

    if cls is None:
        module = classtools.get_calling_module()
        cls = classtools.get_class_from_module(module, Script)

    parser = argument_parser_from_script(cls)
    args = parser.parse_args()
    options = args.__dict__

    verbose = options.pop("verbose", None)
    logging.basicConfig(format='[%(asctime)s] [%(name)s] %(message)s',
                        level=(logging.DEBUG if verbose else logging.INFO))
    logging.getLogger('requests').setLevel(logging.WARN)

    instance = cls(options)

    return instance.run()
예제 #5
0
 def test_get_calling_module(self):
     self.assertEqual(classtools.get_calling_module(depth=0), self.__module__)
예제 #6
0
def _addModulesToSet(targetset, *modules):
    """Add the given modules to the targetset"""
    if not modules: modules = [classtools.get_calling_module(depth=2)]
    targetset.update(modules)
예제 #7
0
 def test_get_calling_module(self):
     self.assertEqual(classtools.get_calling_module(depth=0),
                      self.__module__)
예제 #8
0
파일: cli.py 프로젝트: edisona/amcat
def get_script(depth=2):
    module = classtools.get_calling_module(depth=depth)
    return classtools.get_class_from_module(module, Script)
예제 #9
0
def _addModulesToSet(targetset, *modules):
    """Add the given modules to the targetset"""
    if not modules:
        modules = [classtools.get_calling_module(depth=2)]
    targetset.update(modules)
def get_script(depth=2):
    module = classtools.get_calling_module(depth=depth)
    return classtools.get_class_from_module(module, Script)