def __call__(self, progress, data, width): '''Updates the progress bar and its subcomponents''' left = converters.to_unicode(self.left(progress, data, width)) right = converters.to_unicode(self.right(progress, data, width)) width -= progress.custom_len(left) + progress.custom_len(right) marker = converters.to_unicode(self.marker(progress, data, width)) fill = converters.to_unicode(self.fill(progress, data, width)) if width: # pragma: no branch value = int( data['total_seconds_elapsed'] / self.INTERVAL.total_seconds()) a = value % width b = width - a - 1 if value % (width * 2) >= width: a, b = b, a if self.fill_left: marker = a * fill + marker + b * fill else: marker = b * fill + marker + a * fill return left + marker + right
def __call__(self, progress, data, width): '''Updates the progress bar and its subcomponents''' left = converters.to_unicode(self.left(progress, data, width)) right = converters.to_unicode(self.right(progress, data, width)) width -= progress.custom_len(left) + progress.custom_len(right) marker = converters.to_unicode(self.marker(progress, data, width)) fill = converters.to_unicode(self.fill(progress, data, width)) if self.fill_left: marker = marker.ljust(width, fill) else: marker = marker.rjust(width, fill) return left + marker + right
def _format_widgets(self): result = [] expanding = [] width = self.term_width data = self.data() for index, widget in enumerate(self.widgets): if isinstance(widget, widgets.WidgetBase) \ and not widget.check_size(self): continue elif isinstance(widget, widgets.AutoWidthWidgetBase): result.append(widget) expanding.insert(0, index) elif isinstance(widget, six.string_types): result.append(widget) width -= self.custom_len(widget) else: widget_output = converters.to_unicode(widget(self, data)) result.append(widget_output) width -= self.custom_len(widget_output) count = len(expanding) while expanding: portion = max(int(math.ceil(width * 1. / count)), 0) index = expanding.pop() widget = result[index] count -= 1 widget_output = widget(self, data, portion) width -= self.custom_len(widget_output) result[index] = widget_output return result
def _format_widgets(self): result = [] expanding = [] width = self.term_width data = self.data() for index, widget in enumerate(self.widgets): if isinstance(widget, widgets.AutoWidthWidgetBase): result.append(widget) expanding.insert(0, index) elif isinstance(widget, six.string_types): result.append(widget) width -= self.custom_len(widget) else: widget_output = converters.to_unicode(widget(self, data)) result.append(widget_output) width -= self.custom_len(widget_output) count = len(expanding) while expanding: portion = max(int(math.ceil(width * 1. / count)), 0) index = expanding.pop() widget = result[index] count -= 1 widget_output = widget(self, data, portion) width -= self.custom_len(widget_output) result[index] = widget_output return result
def __call__(self, progress, data, width): '''Updates the progress bar and its subcomponents''' left = converters.to_unicode(self.left(progress, data, width)) right = converters.to_unicode(self.right(progress, data, width)) width -= progress.custom_len(left) + progress.custom_len(right) marker = converters.to_unicode(self.marker(progress, data, width)) fill = converters.to_unicode(self.fill(progress, data, width)) # Make sure we ignore invisible characters when filling width += len(marker) - progress.custom_len(marker) if self.fill_left: marker = marker.ljust(width, fill) else: marker = marker.rjust(width, fill) return left + marker + right
def update(self, *args, **kwargs): ProgressBarMixinBase.update(self, *args, **kwargs) line = converters.to_unicode(self._format_line()) if not self.enable_colors: line = utils.no_color(line) if self.line_breaks: line = line.rstrip() + '\n' else: line = '\r' + line self.fd.write(line)
def test_markers(name, markers, as_unicode): if as_unicode: markers = converters.to_unicode(markers) else: markers = converters.to_str(markers) widgets = [ '%s: ' % name.capitalize(), progressbar.AnimatedMarker(markers=markers), ] pbar = progressbar.ProgressBar(widgets=widgets) for i in pbar((i for i in range(24))): time.sleep(0.001)
def test_markers(name, markers, as_unicode): if as_unicode: markers = converters.to_unicode(markers) else: markers = converters.to_str(markers) widgets = [ '%s: ' % name.capitalize(), progressbar.AnimatedMarker(markers=markers), ] bar = progressbar.ProgressBar(widgets=widgets) bar._MINIMUM_UPDATE_INTERVAL = 1e-12 for i in bar((i for i in range(24))): time.sleep(0.001)
def create_marker(marker): def _marker(progress, data, width): if progress.max_value is not base.UnknownLength \ and progress.max_value > 0: length = int(progress.value / progress.max_value * width) return (marker * length) else: return marker if isinstance(marker, six.string_types): marker = converters.to_unicode(marker) assert len(marker) == 1, 'Markers are required to be 1 char' return _marker else: return marker
def create_marker(marker, wrap=None): def _marker(progress, data, width): if progress.max_value is not base.UnknownLength and progress.max_value > 0: length = int(progress.value / progress.max_value * width) return marker * length else: return marker if isinstance(marker, six.string_types): marker = converters.to_unicode(marker) assert utils.len_color( marker) == 1, "Markers are required to be 1 char" return wrapper(_marker, wrap) else: return wrapper(marker, wrap)
def update(self, *args, **kwargs): ProgressBarMixinBase.update(self, *args, **kwargs) line = converters.to_unicode(self._format_line()) if not self.enable_colors: line = utils.no_color(line) if self.line_breaks: line = line.rstrip() + '\n' else: line = '\r' + line try: # pragma: no cover self.fd.write(line) except UnicodeEncodeError: # pragma: no cover self.fd.write(line.encode('ascii', 'replace'))
def _to_unicode(cls, args): for arg in args: yield converters.to_unicode(arg)
def update(self, *args, **kwargs): ProgressBarMixinBase.update(self, *args, **kwargs) line = converters.to_unicode('\r' + self._format_line()) self.fd.write(line)
def _convert(item): if isinstance(item, list): return [utils.to_unicode(i.value) for i in item] if item.filename: return MultipartFile(item) return utils.to_unicode(item.value)
def __init__(self, storage): self.filename = utils.to_unicode(storage.filename) self.file = storage.file