def info_single(self, message, overwrite_verbose=False, mc='yellow', nl_before=0, nl_after=0, cut_after=80, level=1, progress=None): if isinstance(message, str): message = remove_spaces(message) if level not in self.single_line_prefixes: raise TerminalError( "the `info_single` function does not know how to deal with a level of %d :/" % level) if cut_after: message_line = c( "%s%s\n" % (self.single_line_prefixes[level], textwrap.fill(str(message), cut_after)), mc) else: message_line = c( "%s%s\n" % (self.single_line_prefixes[level], str(message)), mc) message_line = ('\n' * nl_before) + message_line + ('\n' * nl_after) if progress: progress.clear() self.write(message_line, overwrite_verbose=False) progress.update(progress.msg) else: self.write(message_line, overwrite_verbose=False)
def info(self, key, value, quiet=False, display_only=False, nl_before=0, nl_after=0, lc='cyan', mc='yellow'): if not display_only: self.info_dict[key] = value if quiet: return True if type(value) == str: value = remove_spaces(value) if type(value) == int: value = pretty_print(value) label = constants.get_pretty_name(key) info_line = "%s%s %s: %s\n%s" % ('\n' * nl_before, c(label, lc), '.' * (self.width - len(label)), c(str(value), mc), '\n' * nl_after) if self.info_file_obj: self.info_file_obj.write(info_line) if self.verbose: sys.stderr.write(info_line)
def info(self, key, value, quiet=False, display_only=False, overwrite_verbose=False, nl_before=0, nl_after=0, lc='cyan', mc='yellow', progress=None): if not display_only: self.info_dict[key] = value if isinstance(value, bool): pass elif isinstance(value, str): value = remove_spaces(value) elif isinstance(value, int): value = pretty_print(value) label = constants.get_pretty_name(key) info_line = "%s%s %s: %s\n%s" % ('\n' * nl_before, c(label, lc), '.' * (self.width - len(label)), c(str(value), mc), '\n' * nl_after) if progress: progress.clear() self.write(info_line, overwrite_verbose=False, quiet=quiet) progress.update(progress.msg) else: self.write(info_line, quiet=quiet, overwrite_verbose=overwrite_verbose)
def info_single(self, message, mc='yellow', nl_before=0, nl_after=0, cut_after=80): if isinstance(message, str): message = remove_spaces(message) if cut_after: message_line = c("* %s\n" % (textwrap.fill(str(message), cut_after)), mc) else: message_line = c("* %s\n" % str(message), mc) message_line = ('\n' * nl_before) + message_line + ('\n' * nl_after) self.write(message_line)
def warning(self, message, header='WARNING', lc = 'red', raw = False): if type(message) == str: message = remove_spaces(message) message_line = '' header_line = c("\n%s\n%s\n" % (header, '=' * (self.width + 2)), lc) if raw: message_line = c("%s\n\n" % (message), lc) else: message_line = c("%s\n\n" % (textwrap.fill(str(message), 80)), lc) self.write(header_line + message_line)
def info_single(self, message, mc = 'yellow', nl_before = 0, nl_after = 0, cut_after = 80): if type(message) == str: message = remove_spaces(message) if cut_after: message_line = c("* %s\n" % (textwrap.fill(str(message), cut_after)), mc) else: message_line = c("* %s\n" % str(message), mc) message_line = ('\n' * nl_before) + message_line + ('\n' * nl_before) self.write(message_line)
def warning(self, message, header='WARNING', lc='red', raw=False, overwrite_verbose=False): if isinstance(message, str): message = remove_spaces(message) message_line = '' header_line = c("\n%s\n%s\n" % (header, '=' * (self.width + 2)), lc) if raw: message_line = c("%s\n\n" % (message), lc) else: message_line = c("%s\n\n" % (textwrap.fill(str(message), 80)), lc) self.write((header_line + message_line) if message else header_line, overwrite_verbose=overwrite_verbose)
def info_single(self, message, mc = 'yellow', nl_before = 0, nl_after = 0, cut_after = 80): if type(message) == str: message = remove_spaces(message) if cut_after: message_line = c("* %s\n" % (textwrap.fill(str(message), cut_after)), mc) else: message_line = c("* %s\n" % str(message), mc) if self.verbose: sys.stderr.write('\n' * nl_before) sys.stderr.write(message_line) sys.stderr.write('\n' * nl_after)
def info_single(self, message, mc="yellow", nl_before=0, nl_after=0, cut_after=80): if type(message) == str: message = remove_spaces(message) if cut_after: message_line = c("* %s\n" % (textwrap.fill(str(message), cut_after)), mc) else: message_line = c("* %s\n" % str(message), mc) if self.verbose: sys.stderr.write("\n" * nl_before) sys.stderr.write(message_line) sys.stderr.write("\n" * nl_after)
def warning(self, message, header='WARNING', lc='red', raw=False, overwrite_verbose=False, nl_before=0, nl_after=0): if isinstance(message, str): message = remove_spaces(message) message_line = '' header_line = c("%s\n%s\n%s\n" % (('\n' * nl_before), header, '=' * (self.width + 2)), lc) if raw: message_line = c("%s\n\n%s" % ((message), '\n' * nl_after), lc) else: message_line = c("%s\n\n%s" % (textwrap.fill(str(message), 80), '\n' * nl_after), lc) self.write((header_line + message_line) if message else header_line, overwrite_verbose=overwrite_verbose)
def warning(self, message, header="WARNING", lc="red", raw=False): if type(message) == str: message = remove_spaces(message) header_line = c("\n%s\n%s\n" % (header, "=" * (self.width + 2)), lc) if raw: message_line = c("%s\n\n" % (message), lc) else: message_line = c("%s\n\n" % (textwrap.fill(str(message), 80)), lc) if self.verbose: sys.stderr.write(header_line) if message: sys.stderr.write(message_line)
def warning(self, message, header='WARNING', lc='red', raw=False): if type(message) == str: message = remove_spaces(message) header_line = c("\n%s\n%s\n" % (header, '=' * (self.width + 2)), lc) if raw: message_line = c("%s\n\n" % (message), lc) else: message_line = c("%s\n\n" % (textwrap.fill(str(message), 80)), lc) if self.verbose: sys.stderr.write(header_line) if message: sys.stderr.write(message_line)
def info(self, key, value, quiet = False, display_only = False, nl_before = 0, nl_after = 0, lc = 'cyan', mc = 'yellow'): if not display_only: self.info_dict[key] = value if type(value) == str: value = remove_spaces(value) if type(value) == int: value = pretty_print(value) label = constants.get_pretty_name(key) info_line = "%s%s %s: %s\n%s" % ('\n' * nl_before, c(label, lc), '.' * (self.width - len(label)), c(str(value), mc), '\n' * nl_after) self.write(info_line, quiet = quiet)
def warning(self, message, header='WARNING', lc='red', raw=False, overwrite_verbose=False, nl_before=0, nl_after=0, progress=None): if isinstance(message, str): message = remove_spaces(message) message_line = '' header_line = c("%s\n%s\n%s\n" % (('\n' * nl_before), header, '=' * (self.width + 2)), lc) if raw: message_line = c("%s\n\n%s" % ((message), '\n' * nl_after), lc) else: message_line = c("%s\n\n%s" % (textwrap.fill(str(message), 80), '\n' * nl_after), lc) if progress: progress.clear() self.write((header_line + message_line) if message else header_line, overwrite_verbose=overwrite_verbose) if progress.msg and progress.pid: progress.update(progress.msg) else: self.write((header_line + message_line) if message else header_line, overwrite_verbose=overwrite_verbose)
def info(self, key, value, quiet=False, display_only=False, lc="cyan", mc="yellow"): if not display_only: self.info_dict[key] = value if quiet: return True if type(value) == str: value = remove_spaces(value) if type(value) == int: value = pretty_print(value) label = constants.get_pretty_name(key) info_line = "%s %s: %s\n" % (c(label, lc), "." * (self.width - len(label)), c(str(value), mc)) if self.info_file_obj: self.info_file_obj.write(info_line) if self.verbose: sys.stderr.write(info_line)
def info_single(self, message, mc='yellow', nl_before=0, nl_after=0, cut_after=80, level=1, progress=None): if isinstance(message, str): message = remove_spaces(message) if level not in self.single_line_prefixes: raise TerminalError("the `info_single` function does not know how to deal with a level of %d :/" % level) if cut_after: message_line = c("%s%s\n" % (self.single_line_prefixes[level], textwrap.fill(str(message), cut_after)), mc) else: message_line = c("%s%s\n" % (self.single_line_prefixes[level], str(message)), mc) message_line = ('\n' * nl_before) + message_line + ('\n' * nl_after) if progress: progress.clear() self.write(message_line) progress.update(progress.msg) else: self.write(message_line)
def info(self, key, value, quiet=False, display_only=False, nl_before=0, nl_after=0, lc='cyan', mc='yellow', progress=None): if not display_only: self.info_dict[key] = value if isinstance(value, bool): pass elif isinstance(value, str): value = remove_spaces(value) elif isinstance(value, int): value = pretty_print(value) label = constants.get_pretty_name(key) info_line = "%s%s %s: %s\n%s" % ('\n' * nl_before, c(label, lc), '.' * (self.width - len(label)), c(str(value), mc), '\n' * nl_after) if progress: progress.clear() self.write(info_line, quiet=quiet) progress.update(progress.msg) else: self.write(info_line, quiet=quiet)
def info(self, key, value, quiet=False, display_only=False, overwrite_verbose=False, nl_before=0, nl_after=0, lc='cyan', mc='yellow', progress=None, align_long_values=True): """ This function prints information nicely to the terminal in the form: key ........: value PARAMETERS ========== key : str what to print before the dots value : str what to print after the dots quiet : boolean the standard anvi'o quiet parameter which, if True, suppresses some output display_only : boolean if False, the key value pair is also stored in the info dictionary overwrite_verbose : boolean if True, downstream quiet parameters (though not the global --quiet) are ignored to produce more verbose output nl_before : int number of lines to print before the key-value line nl_after : int number of lines to print after the key-value line lc : color str the color of the label (key) mc : color str the color of the value progress : Progress instance provides the Progress bar to use align_long_values : boolean if True, values that are longer than the terminal width will be broken up into different lines that align nicely """ if not display_only: self.info_dict[key] = value if value is None: value = "None" elif isinstance(value, bool) or isinstance(value, float) or isinstance( value, list): value = "%s" % value elif isinstance(value, str): value = remove_spaces(value) elif isinstance(value, int): value = pretty_print(value) label = constants.get_pretty_name(key) info_line = "%s%s %s: %s\n%s" % ('\n' * nl_before, c(label, lc), '.' * (self.width - len(label)), c(str(value), mc), '\n' * nl_after) if align_long_values: terminal_width = get_terminal_size()[0] wrap_width = terminal_width - self.width - 3 wrapped_value_lines = textwrap.wrap(value, width=wrap_width, break_long_words=False, break_on_hyphens=False) if len(wrapped_value_lines) == 0: aligned_value_str = value else: aligned_value_str = wrapped_value_lines[0] for line in wrapped_value_lines[1:]: aligned_value_str += "\n %s %s" % (' ' * self.width, line) info_line = "%s%s %s: %s\n%s" % ( '\n' * nl_before, c(label, lc), '.' * (self.width - len(label)), c(str(aligned_value_str), mc), '\n' * nl_after) if progress: progress.clear() self.write(info_line, overwrite_verbose=False, quiet=quiet) progress.update(progress.msg) else: self.write(info_line, quiet=quiet, overwrite_verbose=overwrite_verbose)