On Wed, May 14, 2014 at 03:24:20PM +0100, Lars Wirzenius wrote:
On Wed, May 14, 2014 at 03:18:26PM +0100, Richard Ipsum wrote:
> On Wed, May 14, 2014 at 02:57:28PM +0100, Lars Wirzenius wrote:
> > On Wed, May 14, 2014 at 01:52:17PM +0100, Richard Ipsum wrote:
> > > try:
> > > - return self._app.runcmd(real_argv, **kwargs)
> > > + if 'logfile' in kwargs:
> > > + logfile = kwargs['logfile']
> > > + del kwargs['logfile']
> > > +
> > > + if logfile:
> > > + teecmd = ['tee', '-a', logfile]
> > > + return self._app.runcmd(real_argv, teecmd, **kwargs)
> > > + else:
> > > + return self._app.runcmd(real_argv, **kwargs)
> > > except cliapp.AppException as e:
> > > raise cliapp.AppException('In staging area %s: running
'
> > > 'command \'%s\'
failed.' %
> >
> > What happens if kwargs does not contain logfile? Looks to me like the
> > code doesn't run anything at all then.
>
> Thanks for spotting this, that 'if logfile' block is not supposed to be
> indented, raising it one indentation level should fix it.
Will the variable logfile exist in that case? Would it be simpler to
have this structure:
I'd need to set logfile to None as well.
if 'loglife' in kwargs:
... setup teecmd and call runcmd
else:
... call runcmd without tee
That is, no nesteds ifs?
I agree that this is a better way to do it, I'll do it this way.