From: Felix Schwarz Date: Sat, 5 Mar 2011 14:53:03 +0000 (+0000) Subject: shorten the __init__() method of !CommandLineInterface by extracting the logging... X-Git-Tag: 1.0~215 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ff28b7bab1cf78632b6f26e043f39a671bfeaac;p=thirdparty%2Fbabel.git shorten the __init__() method of !CommandLineInterface by extracting the logging configuration into another method --- diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index d6b85515..fc6216d8 100755 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -626,21 +626,7 @@ class CommandLineInterface(object): options, args = self.parser.parse_args(argv[1:]) - # Configure logging - self.log = logging.getLogger('babel') - self.log.setLevel(options.loglevel) - # Don't add a new handler for every instance initialization (#227), this - # would cause duplicated output when the CommandLineInterface as an - # normal Python class. - if self.log.handlers: - handler = self.log.handlers[0] - else: - handler = logging.StreamHandler() - self.log.addHandler(handler) - handler.setLevel(options.loglevel) - formatter = logging.Formatter('%(message)s') - handler.setFormatter(formatter) - + self._configure_logging(options.loglevel) if options.list_locales: identifiers = localedata.list() longest = max([len(identifier) for identifier in identifiers]) @@ -664,6 +650,21 @@ class CommandLineInterface(object): return getattr(self, cmdname)(args[1:]) + def _configure_logging(self, loglevel): + self.log = logging.getLogger('babel') + self.log.setLevel(loglevel) + # Don't add a new handler for every instance initialization (#227), this + # would cause duplicated output when the CommandLineInterface as an + # normal Python class. + if self.log.handlers: + handler = self.log.handlers[0] + else: + handler = logging.StreamHandler() + self.log.addHandler(handler) + handler.setLevel(loglevel) + formatter = logging.Formatter('%(message)s') + handler.setFormatter(formatter) + def _help(self): print self.parser.format_help() print "commands:"