def status_iterator(self, iterable, summary, colorfunc=darkgreen, length=0, stringify_func=_display_chunk): if length == 0: for item in self.old_status_iterator(iterable, summary, colorfunc, stringify_func): yield item return l = 0 summary = bold(summary) for item in iterable: l += 1 s = '%s[%3d%%] %s' % (summary, 100 * l / length, colorfunc(stringify_func(item))) if self.verbosity: s += '\n' else: s = term_width_line(s) self.info(s, nonl=1) yield item if l > 0: self.info()
def status_iterator(iterable, summary, color="darkgreen", length=0, verbosity=0, stringify_func=display_chunk): # type: (Iterable, unicode, str, int, int, Callable[[Any], unicode]) -> Iterable # NOQA if length == 0: for item in old_status_iterator(iterable, summary, color, stringify_func): yield item return l = 0 summary = bold(summary) for item in iterable: l += 1 s = '%s[%3d%%] %s' % (summary, 100 * l / length, colorize(color, stringify_func(item))) if verbosity: s += '\n' else: s = term_width_line(s) logger.info(s, nonl=True) yield item if l > 0: logger.info('')
def status_iterator( iterable: Iterable, summary: str, color: str = "darkgreen", length: int = 0, verbosity: int = 0, stringify_func: Callable[[Any], str] = display_chunk) -> Iterable: if length == 0: yield from old_status_iterator(iterable, summary, color, stringify_func) return l = 0 summary = bold(summary) for item in iterable: l += 1 s = '%s[%3d%%] %s' % (summary, 100 * l / length, colorize(color, stringify_func(item))) if verbosity: s += '\n' else: s = term_width_line(s) logger.info(s, nonl=True) yield item if l > 0: logger.info('')
def status_iterator(mapping: Mapping[str, str], summary: str, color: str = "darkgreen", length: int = 0, verbosity: int = 0) -> Tuple[str, str]: """ Displays the status of iterating through a Dict/Mapping of strings. Taken from the Sphinx sources. Status includes percent of records in the iterable that have been iterated through. :param mapping: The iterable to iterate through :param summary: A description of the action or operation :param color: The color of the status text; defaults to `darkgreen` :param length: The number of records in the iterable :param verbosity: Flag which writes a newline after each status message :return: A tuple containing the next key-value pair from the iterable """ if length == 0: yield from old_status_iterator(mapping, summary, color) return line_count = 0 summary = bold(summary) for item in mapping.items(): line_count += 1 s = '%s[%3d%%] %s' % (summary, 100 * line_count / length, colorize(color, item[0])) if verbosity: s += '\n' else: s = term_width_line(s) logger.info(s, nonl=True) yield item if line_count > 0: logger.info('')
def progress(response: PipelineResponse) -> None: """Download progress callback.""" mb_tot = response.context["data_stream_total"] / (1024 * 1024) mb_curr = response.context["download_stream_current"] / (1024 * 1024) pct = int((mb_curr / mb_tot) * 100) s = term_width_line( bold("Downloading cache files... ") + f"{mb_curr:.2f} of {mb_tot:.2f} Mb [{pct} %]") logger.info(s, nonl=pct < 100)
def status_iterator(self, iterable, summary, colorfunc=darkgreen, length=0): if length == 0: for item in self.old_status_iterator(iterable, summary, colorfunc): yield item return l = 0 summary = bold(summary) for item in iterable: l += 1 self.info(term_width_line('%s[%3d%%] %s' % (summary, 100*l/length, colorfunc(item))), nonl=1) yield item if l > 0: self.info()
def status_iterator(self, iterable, summary, colorfunc=darkgreen, length=0, stringify_func=lambda x: x): if length == 0: for item in self.old_status_iterator(iterable, summary, colorfunc, stringify_func): yield item return l = 0 summary = bold(summary) for item in iterable: l += 1 s = "%s[%3d%%] %s" % (summary, 100 * l / length, colorfunc(stringify_func(item))) if self.app.verbosity: s += "\n" else: s = term_width_line(s) self.info(s, nonl=1) yield item if l > 0: self.info()
def status_iterator(iterable, summary, color="darkgreen", length=0, verbosity=0, stringify_func=display_chunk): # type: (Iterable, str, str, int, int, Callable[[Any], str]) -> Iterable if length == 0: yield from old_status_iterator(iterable, summary, color, stringify_func) return l = 0 summary = bold(summary) for item in iterable: l += 1 s = '%s[%3d%%] %s' % (summary, 100 * l / length, colorize(color, stringify_func(item))) if verbosity: s += '\n' else: s = term_width_line(s) logger.info(s, nonl=True) yield item if l > 0: logger.info('')
def status_iterator(self, iterable, summary, colorfunc=darkgreen, length=0): if length == 0: for item in self.old_status_iterator(iterable, summary, colorfunc): yield item return l = 0 summary = bold(summary) for item in iterable: l += 1 self.info(term_width_line( '%s[%3d%%] %s' % (summary, 100 * l / length, colorfunc(item))), nonl=1) yield item if l > 0: self.info()
def status_iterator(self, iterable, summary, colorfunc=darkgreen, length=0, stringify_func=_display_chunk): # type: (Iterable, unicode, Callable, int, Callable) -> Iterable if length == 0: for item in self.old_status_iterator(iterable, summary, colorfunc, stringify_func): yield item return l = 0 summary = bold(summary) for item in iterable: l += 1 s = '%s[%3d%%] %s' % (summary, 100*l/length, colorfunc(stringify_func(item))) if self.verbosity: s += '\n' else: s = term_width_line(s) self.info(s, nonl=True) yield item if l > 0: self.info()
def log_nonl(msg): _LOG.info(term_width_line(msg), nonl=True)