portage.output module¶
- class portage.output.ConsoleStyleFile(f)¶
Bases:
object
A file-like object that behaves something like the colorize() function. Style identifiers passed in via the new_styles() method will be used to apply console codes to output.
- _write(f, s)¶
- close()¶
- flush()¶
- new_styles(styles)¶
- write(s)¶
- writelines(lines)¶
- class portage.output.EOutput(quiet=False)¶
Bases:
object
Performs fancy terminal formatting for status and informational messages.
The provided methods produce identical terminal output to the eponymous functions in the shell script
/sbin/functions.sh
and also accept identical parameters.This is not currently a drop-in replacement however, as the output-related functions in
/sbin/functions.sh
are oriented for use mainly by system init scripts and ebuilds and their output can be customized via certainRC_*
environment variables (see/etc/conf.d/rc
). B{EOutput} is not customizable in this manner since it’s intended for more general uses. Likewise, no logging is provided.@ivar quiet: Specifies if output should be silenced. :type quiet: BooleanType @ivar term_columns: Width of terminal in characters. Defaults to the value
specified by the shell’s
COLUMNS
variable, else to the queried tty size, else to80
.- __eend(caller, errno, msg)¶
- _write(f, s)¶
- ebegin(msg)¶
Shows a message indicating the start of a process.
- Parameters
msg (StringType) – A very brief (shorter than one line) description of the starting process.
- eend(errno, *msg)¶
Indicates the completion of a process, optionally displaying a message via
eerror
if the process’s exit status isn’t0
.- Parameters
errno (IntType) – A standard UNIX
errno
code returned by processes upon exit.msg (StringType) – I{(optional)} An error message, typically a standard UNIX error string corresponding to
errno
.
- eerror(msg)¶
Shows an error message.
- Parameters
msg (StringType) – A very brief (shorter than one line) error message.
- einfo(msg)¶
Shows an informative message terminated with a newline.
- Parameters
msg (StringType) – A very brief (shorter than one line) informative message.
- einfon(msg)¶
Shows an informative message terminated without a newline.
- Parameters
msg (StringType) – A very brief (shorter than one line) informative message.
- elog(msg)¶
Shows a logged informative message terminated with a newline.
- Parameters
msg (StringType) – A very brief (shorter than one line) informative message.
- eqawarn(msg)¶
Shows a QA warning.
- Parameters
msg (StringType) – A very brief (shorter than one line) warning message.
- ewarn(msg)¶
Shows a warning message.
- Parameters
msg (StringType) – A very brief (shorter than one line) warning message.
- ewend(errno, *msg)¶
Indicates the completion of a process, optionally displaying a message via
ewarn
if the process’s exit status isn’t0
.- Parameters
errno (IntType) – A standard UNIX
errno
code returned by processes upon exit.msg (StringType) – I{(optional)} A warning message, typically a standard UNIX error string corresponding to
errno
.
- class portage.output.ProgressBar(title=None, maxval=0, label=None, max_desc_length=25)¶
Bases:
object
The interface is copied from the ProgressBar class from the EasyDialogs module (which is Mac only).
- _set_desc()¶
- property curval¶
The current value (of type integer or long integer) of the progress bar. The normal access methods coerce curval between 0 and maxval. This attribute should not be altered directly.
- inc(n=1)¶
Increments the progress bar’s curval by n, or by 1 if n is not provided. (Note that n may be negative, in which case the effect is a decrement.) The progress bar is updated to reflect the change. If the bar is indeterminate, this causes one ``spin’’ of the barber pole. The resulting curval is coerced between 0 and maxval if incrementing causes it to fall outside this range.
- label(newstr)¶
Sets the text in the progress box of the progress dialog to newstr.
- property maxval¶
The maximum value (of type integer or long integer) of the progress bar; the progress bar (thermometer style) is full when curval equals maxval. If maxval is 0, the bar will be indeterminate (barber-pole). This attribute should not be altered directly.
- set(value, maxval=None)¶
Sets the progress bar’s curval to value, and also maxval to max if the latter is provided. value is first coerced between 0 and maxval. The thermometer bar is updated to reflect the changes, including a change from indeterminate to determinate or vice versa.
- title(newstr)¶
Sets the text in the title bar of the progress dialog to newstr.
- class portage.output.StyleWriter(**kwargs)¶
Bases:
portage.util.formatter.DumbWriter
This is just a DumbWriter with a hook in the new_styles() method that passes a styles tuple as a single argument to a callable style_listener attribute.
- flush()¶
- new_styles(styles)¶
- send_line_break()¶
- send_literal_data(data)¶
- class portage.output.TermProgressBar(fd=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, **kwargs)¶
Bases:
portage.output.ProgressBar
A tty progress bar similar to wget’s.
- _create_image()¶
- _display_image(image)¶
- _set_desc()¶
- property curval¶
The current value (of type integer or long integer) of the progress bar. The normal access methods coerce curval between 0 and maxval. This attribute should not be altered directly.
- inc(n=1)¶
Increments the progress bar’s curval by n, or by 1 if n is not provided. (Note that n may be negative, in which case the effect is a decrement.) The progress bar is updated to reflect the change. If the bar is indeterminate, this causes one ``spin’’ of the barber pole. The resulting curval is coerced between 0 and maxval if incrementing causes it to fall outside this range.
- label(newstr)¶
Sets the text in the progress box of the progress dialog to newstr.
- property maxval¶
The maximum value (of type integer or long integer) of the progress bar; the progress bar (thermometer style) is full when curval equals maxval. If maxval is 0, the bar will be indeterminate (barber-pole). This attribute should not be altered directly.
- set(value, maxval=None)¶
Sets the progress bar’s curval to value, and also maxval to max if the latter is provided. value is first coerced between 0 and maxval. The thermometer bar is updated to reflect the changes, including a change from indeterminate to determinate or vice versa.
- title(newstr)¶
Sets the text in the title bar of the progress dialog to newstr.
- class portage.output._LazyInitColorMap(attr)¶
Bases:
portage.proxy.objectproxy.ObjectProxy
- _attr¶
- _get_target()¶
- portage.output._init(config_root='/')¶
Load color.map from the given config_root. This is called automatically on first access of the codes or _styles attributes (unless it has already been called for some other reason).
- portage.output._parse_color_map(config_root='/', onerror=None)¶
Parse /etc/portage/color.map and return a dict of error codes.
- Parameters
onerror (callable) – an optional callback to handle any ParseError that would otherwise be raised
- Return type
dict
- Returns
a dictionary mapping color classes to color codes
- portage.output._styles = {'BAD': ('red',), 'BRACKET': ('blue',), 'ERR': ('red',), 'GOOD': ('green',), 'HILITE': ('teal',), 'INFO': ('darkgreen',), 'INFORM': ('darkgreen',), 'LOG': ('green',), 'MERGE_LIST_PROGRESS': ('yellow',), 'NORMAL': ('normal',), 'PKG_BINARY_MERGE': ('purple',), 'PKG_BINARY_MERGE_SYSTEM': ('purple',), 'PKG_BINARY_MERGE_WORLD': ('fuchsia',), 'PKG_BLOCKER': ('red',), 'PKG_BLOCKER_SATISFIED': ('teal',), 'PKG_MERGE': ('darkgreen',), 'PKG_MERGE_SYSTEM': ('darkgreen',), 'PKG_MERGE_WORLD': ('green',), 'PKG_NOMERGE': ('teal',), 'PKG_NOMERGE_SYSTEM': ('teal',), 'PKG_NOMERGE_WORLD': ('blue',), 'PKG_UNINSTALL': ('red',), 'PROMPT_CHOICE_DEFAULT': ('green',), 'PROMPT_CHOICE_OTHER': ('red',), 'QAWARN': ('brown',), 'SECURITY_WARN': ('red',), 'UNMERGE_WARN': ('red',), 'WARN': ('yellow',)}¶
Maps attribute name to ansi code.
- portage.output.color(fg, bg='default', attr=['normal'])¶
- portage.output.colorize(color_key, text)¶
- portage.output.colormap()¶
- portage.output.dotitles = 1¶
Maps style class to tuple of attribute names.
- portage.output.get_term_size(fd=None)¶
Get the number of lines and columns of the tty that is connected to fd. Returns a tuple of (lines, columns) or (0, 0) if an error occurs. The curses module is used if available, otherwise the output of stty size is parsed. The lines and columns values are guaranteed to be greater than or equal to zero, since a negative COLUMNS variable is known to prevent some commands from working (see bug #394091).
- portage.output.nc_len(mystr)¶
- portage.output.nocolor()¶
turn off colorization
- portage.output.notitles()¶
turn off title setting
- portage.output.resetColor()¶
- portage.output.set_term_size(lines, columns, fd)¶
Set the number of lines and columns for the tty that is connected to fd. For portability, this simply calls stty rows $lines columns $columns.
- portage.output.style_to_ansi_code(style)¶
- Parameters
style (String) – A style name
- Return type
String
- Returns
A string containing one or more ansi escape codes that are used to render the given style.
- portage.output.xtermTitle(mystr, raw=False)¶
- portage.output.xtermTitleReset()¶