def main(args=None): old_level = logger.level old_handlers = list(logger.handlers) try: dispatcher = Dispatcher(args) if dispatcher.action is None: return return dispatcher() except KeyboardInterrupt: logger.info('interrupted') return 1 except (IOError, os.error, PackagingError, CCompilerError) as exc: logger.exception(exc) return 1 finally: logger.setLevel(old_level) logger.handlers[:] = old_handlers
def _set_logger(self): # setting up the logging level from the command-line options # -q gets warning, error and critical if self.verbose == 0: level = logging.WARNING # default level or -v gets info too # XXX there's a bug somewhere: the help text says that -v is default # (and verbose is set to 1 above), but when the user explicitly gives # -v on the command line, self.verbose is incremented to 2! Here we # compensate for that (I tested manually). On a related note, I think # it's a good thing to use -q/nothing/-v/-vv on the command line # instead of logging constants; it will be easy to add support for # logging configuration in setup.cfg for advanced users. --merwok elif self.verbose in (1, 2): level = logging.INFO else: # -vv and more for debug level = logging.DEBUG # setting up the stream handler handler = logging.StreamHandler(sys.stderr) handler.setLevel(level) logger.addHandler(handler) logger.setLevel(level)
if self.action is None: return for action, desc, func in actions: if action == self.action: return func(self, self.args) return -1 def main(args=None): old_level = logger.level old_handlers = list(logger.handlers) try: dispatcher = Dispatcher(args) if dispatcher.action is None: return return dispatcher() except KeyboardInterrupt: logger.info('interrupted') return 1 except (IOError, os.error, PackagingError, CCompilerError), exc: logger.exception(exc) return 1 finally: logger.setLevel(old_level) logger.handlers[:] = old_handlers if __name__ == '__main__': sys.exit(main())