[virt-tools-list] [virt-manager] [PATCH] virtinst: progress: Simplify if-statement

Cole Robinson crobinso at redhat.com
Sat Mar 3 21:31:48 UTC 2018


On 03/02/2018 03:12 AM, Radostin Stoyanov wrote:
> Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
> ---
>  virtinst/progress.py | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)
> 
> diff --git a/virtinst/progress.py b/virtinst/progress.py
> index 29bff358..4284f854 100644
> --- a/virtinst/progress.py
> +++ b/virtinst/progress.py
> @@ -253,10 +253,8 @@ class TextMeter(BaseMeter):
>  
>          # Include text + ui_rate in minimal
>          tl = TerminalLine(8, 8+1+8)
> -        if tl._llen > 80:
> -            use_hours = True # For big screens, make it more readable.
> -        else:
> -            use_hours = False
> +        # For big screens, make it more readable.
> +        use_hours = bool(tl._llen > 80)
>          ui_size = tl.add(' | %5sB' % fread)
>          if self.size is None:
>              ui_time = tl.add('  %s' % format_time(etime, use_hours))
> @@ -301,10 +299,8 @@ class TextMeter(BaseMeter):
>              text = self.basename
>  
>          tl = TerminalLine(8)
> -        if tl._llen > 80:
> -            use_hours = True # For big screens, make it more readable.
> -        else:
> -            use_hours = False
> +        # For big screens, make it more readable.
> +        use_hours = bool(tl._llen > 80)
>          ui_size = tl.add(' | %5sB' % total_size)
>          ui_time = tl.add('  %s' % format_time(self.re.elapsed_time(), use_hours))
>          ui_end, not_done = _term_add_end(tl, self.size, amount_read)
> 

ACK and pushed, but some history here: we used python-urlgrabber for
this code for a long time, but that library is dead and won't be ported
to python3 so I copied out the minimal amount we needed and ported the
rest to requests. Basically this code is in maintenance mode, hence the
drastic style differences between it and the rest of the code.

Before the next release I plan to investigate using another progressbar
lib. I think tqdm is my first stop, it's used by twine which is a very
widespread tool and seems to be available just about everywhere and very
meticulously maintained.

Of course if someone wants to beat me to it I won't complain :)

Thanks,
Cole




More information about the virt-tools-list mailing list