Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
N_BARS = max(1, ncols - len(l_bar) - len(r_bar)) if ncols \
else 10
# format bar depending on availability of unicode/ascii chars
if ascii:
bar_length, frac_bar_length = divmod(
int(frac * N_BARS * 10), 10)
bar = '#' * bar_length
frac_bar = chr(48 + frac_bar_length) if frac_bar_length \
else ' '
else:
bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)
bar = _unich(0x2588) * bar_length
frac_bar = _unich(0x2590 - frac_bar_length) \
if frac_bar_length else ' '
# whitespace padding
if bar_length < N_BARS:
full_bar = bar + frac_bar + \
' ' * max(N_BARS - bar_length - 1, 0)
else:
full_bar = bar + \
' ' * max(N_BARS - bar_length, 0)
if bar_format is None:
# Default bar format = fast display
return l_bar + full_bar + r_bar
else:
# Custom bar formatting
elif ascii:
# get the remainder of the division of current fraction with number of symbols
# this will tell us which symbol we should pick
bar_length, frac_bar_length = divmod(
int(frac * N_BARS * 10), 10)
bar = '#' * bar_length
frac_bar = chr(48 + frac_bar_length) if frac_bar_length \
else ' '
# unicode format (if available)
else:
bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)
bar = _unich(0x2588) * bar_length
frac_bar = _unich(0x2590 - frac_bar_length) \
if frac_bar_length else ' '
# whitespace padding
if bar_length < N_BARS:
full_bar = bar + frac_bar + \
' ' * max(N_BARS - bar_length - len(frac_bar), 0)
else:
full_bar = bar + \
' ' * max(N_BARS - bar_length, 0)
# Piece together the bar parts
return l_bar + full_bar + r_bar
# no total: no progressbar, ETA, just progress stats
else:
if bar_format and isinstance(bar_format, dict):
# ascii format
elif ascii:
# get the remainder of the division of current fraction with number of symbols
# this will tell us which symbol we should pick
bar_length, frac_bar_length = divmod(
int(frac * N_BARS * 10), 10)
bar = '#' * bar_length
frac_bar = chr(48 + frac_bar_length) if frac_bar_length \
else ' '
# unicode format (if available)
else:
bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)
bar = _unich(0x2588) * bar_length
frac_bar = _unich(0x2590 - frac_bar_length) \
if frac_bar_length else ' '
# whitespace padding
if bar_length < N_BARS:
full_bar = bar + frac_bar + \
' ' * max(N_BARS - bar_length - len(frac_bar), 0)
else:
full_bar = bar + \
' ' * max(N_BARS - bar_length, 0)
# Piece together the bar parts
return l_bar + full_bar + r_bar
# no total: no progressbar, ETA, just progress stats
else:
if total:
frac = bar_args['frac']
percentage = bar_args['percentage']
remaining_str = bar_args['remaining']
N_BARS = bar_args['n_bars']
# custom symbols format
# need to provide both ascii and unicode versions of custom symbols
if bar_format and isinstance(bar_format, dict):
# get ascii or unicode template
if ascii:
c_symb = bar_format['symbols'].get('ascii', list("123456789#"))
else:
c_symb = bar_format['symbols'].get('unicode', map(_unich, range(0x258F, 0x2587, -1)))
# looping symbols: just update the symbol animation at each iteration
if bar_format['symbols'].get('loop', False):
# increment one step in the animation for each display
self.n_anim += 1
# Get current bar animation
bar = c_symb[divmod(self.n_anim, len(c_symb))[1]]
bar_lines = bar.splitlines()
c_width = len(bar_lines[0]) # all lines should have same len
# Generate bar with left filling space
l_bar_fill = ' ' * len(l_bar)
r_bar_fill = ' ' * len(r_bar)
bar_lines = bar.splitlines() # split bar again because it may have been reversed
middle_bar = int(len(bar_lines) / 2)
# Construct final bar line by line: print the bar status at the middle, otherwise print only the symbol animation on the other lines and fill with blanks to correctly position the symbol.
else 10
# format bar depending on availability of unicode/ascii chars
if ascii:
bar_length, frac_bar_length = divmod(
int(frac * N_BARS * 10), 10)
bar = '#' * bar_length
frac_bar = chr(48 + frac_bar_length) if frac_bar_length \
else ' '
else:
bar_length, frac_bar_length = divmod(int(frac * N_BARS * 8), 8)
bar = _unich(0x2588) * bar_length
frac_bar = _unich(0x2590 - frac_bar_length) \
if frac_bar_length else ' '
# whitespace padding
if bar_length < N_BARS:
full_bar = bar + frac_bar + \
' ' * max(N_BARS - bar_length - 1, 0)
else:
full_bar = bar + \
' ' * max(N_BARS - bar_length, 0)
if bar_format is None:
# Default bar format = fast display
return l_bar + full_bar + r_bar
else:
# Custom bar formatting
# Populate a dict with all available progress indicators