From 58e62320f56400040e0aaa4a3522a50508104b19 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 11 Apr 2016 13:28:37 +0300 Subject: [PATCH] Make the command-line frontend easier to test --- babel/messages/frontend.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py index 3cacec9d..acf4a5fe 100644 --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -720,6 +720,8 @@ class CommandLineInterface(object): 'update': update_catalog, } + log = None # Replaced on instance level + def run(self, argv=None): """Main entry point of the command-line interface. @@ -768,7 +770,8 @@ class CommandLineInterface(object): if cmdname not in self.commands: self.parser.error('unknown command "%s"' % cmdname) - return self._dispatch(cmdname, args[1:]) + cmdinst = self._configure_command(cmdname, args[1:]) + return cmdinst.run() def _configure_logging(self, loglevel): self.log = logging.getLogger('babel') @@ -794,14 +797,15 @@ class CommandLineInterface(object): for name, description in commands: print(format % (name, description)) - def _dispatch(self, cmdname, argv): + def _configure_command(self, cmdname, argv): """ :type cmdname: str :type argv: list[str] """ cmdclass = self.command_classes[cmdname] cmdinst = cmdclass() - cmdinst.log = self.log # Use our logger, not distutils'. + if self.log: + cmdinst.log = self.log # Use our logger, not distutils'. assert isinstance(cmdinst, Command) cmdinst.initialize_options() @@ -837,7 +841,7 @@ class CommandLineInterface(object): except DistutilsOptionError as err: parser.error(str(err)) - cmdinst.run() + return cmdinst def main(): -- 2.47.3