# HG changeset patch # User fschwarz # Date 1299336783 0 # Node ID 81e35b223dd64e9b5c326f8e353fc37cf7ae1d6a # Parent 918569a5a855d7f501b292358f436892b4a0fd3d 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 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -626,21 +626,7 @@ 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 @@ 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:"