[PATCH 1/2] retag: Don't use BaseCommand's stdin/stdout wrappers
Finucane, Stephen
stephen.finucane at intel.com
Tue Nov 10 01:53:36 AEDT 2015
> -----Original Message-----
> From: Lespiau, Damien
> Sent: Monday, November 9, 2015 4:54 AM
> To: Finucane, Stephen
> Cc: patchwork at lists.ozlabs.org
> Subject: Re: [PATCH 1/2] retag: Don't use BaseCommand's stdin/stdout
> wrappers
>
> On Mon, Nov 09, 2015 at 02:29:57AM +0000, Finucane, Stephen wrote:
> > > @@ -38,6 +39,6 @@ class Command(BaseCommand):
> > > for i, patch in enumerate(query.iterator()):
> > > patch.refresh_tag_counts()
> > > if (i % 10) == 0 or i == count:
> > > - self.stdout.write('%06d/%06d\r' % (i, count))
> > > - self.stdout.flush()
> > > - self.stderr.write('\ndone\n')
> > > + sys.stdout.write('%06d/%06d\r' % (i, count))
> > > + sys.stdout.flush()
> > > + sys.stdout.write('\ndone\n')
> >
> > Agree on stderr - > stdout, however Django documentation advises we
> > use the BaseCommand versions hence my original change:
> >
> > https://docs.djangoproject.com/en/1.8/howto/custom-management-
> commands/#management-commands-output
> >
> > Can you just drop the trailing newline instead?
>
> You're missing the point:
>
> > > I noted that it wasn't all trivial changes. And indeed using the
> > > stdin/stdout wrappers change the intended behaviour by adding a new
> > > line.
>
> self.stdout.write('%06d/%06d\r' % (i, count))
>
> That will append a new line, where the intention was to have a progress
> indicator on one line ('\r').
Ah, I get the point - I just misinterpreted the line ending character
(it's a '\r', but I instinctively saw a '\n'). How about this?
self.stdout.write('%06d/%06d\r' % (i, count), ending='')
or this, if you prefer:
self.stdout.write('%06d/%06d' % (i, count), ending='\r')
I'm raising this issue just because the Django docs explicitly say to use
these wrappers.
Stephen
> --
> Damien
More information about the Patchwork
mailing list