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 certain RC_* 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 to 80.

__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’t 0.

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.

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’t 0.

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',), 'GOOD': ('green',), 'HILITE': ('teal',), 'INFORM': ('darkgreen',), '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': ('darkblue',), 'PKG_MERGE': ('darkgreen',), 'PKG_MERGE_SYSTEM': ('darkgreen',), 'PKG_MERGE_WORLD': ('green',), 'PKG_NOMERGE': ('darkblue',), 'PKG_NOMERGE_SYSTEM': ('darkblue',), 'PKG_NOMERGE_WORLD': ('blue',), 'PKG_UNINSTALL': ('red',), 'PROMPT_CHOICE_DEFAULT': ('green',), 'PROMPT_CHOICE_OTHER': ('red',), 'SECURITY_WARN': ('red',), 'UNMERGE_WARN': ('red',), 'WARN': ('yellow',)}

Maps style class to tuple of attribute names.

portage.output.codes = {'0x000000': '\x1b[30m', '0x0000AA': '\x1b[34m', '0x00AA00': '\x1b[32m', '0x00AAAA': '\x1b[36m', '0x555555': '\x1b[30;01m', '0x5555FF': '\x1b[34;01m', '0x55FF55': '\x1b[32;01m', '0x55FFFF': '\x1b[36;01m', '0xAA0000': '\x1b[31m', '0xAA00AA': '\x1b[35m', '0xAA5500': '\x1b[33m', '0xAAAA00': '\x1b[33m', '0xAAAAAA': '\x1b[37m', '0xFF5555': '\x1b[31;01m', '0xFF55FF': '\x1b[35;01m', '0xFFFF55': '\x1b[33;01m', '0xFFFFFF': '\x1b[37;01m', 'bg_black': '\x1b[40m', 'bg_brown': '\x1b[43m', 'bg_darkblue': '\x1b[44m', 'bg_darkgreen': '\x1b[42m', 'bg_darkred': '\x1b[41m', 'bg_darkyellow': '\x1b[43m', 'bg_default': '\x1b[49m', 'bg_lightgray': '\x1b[47m', 'bg_purple': '\x1b[45m', 'bg_teal': '\x1b[46m', 'black': '\x1b[30m', 'blink': '\x1b[05m', 'blue': '\x1b[34;01m', 'bold': '\x1b[01m', 'brown': '\x1b[33m', 'darkblue': '\x1b[34m', 'darkgray': '\x1b[30;01m', 'darkgreen': '\x1b[32m', 'darkred': '\x1b[31m', 'darkteal': '\x1b[36;01m', 'darkyellow': '\x1b[33m', 'faint': '\x1b[02m', 'fuchsia': '\x1b[35;01m', 'green': '\x1b[32;01m', 'invisible': '\x1b[08m', 'lightgray': '\x1b[37m', 'no-attr': '\x1b[22m', 'no-blink': '\x1b[25m', 'no-overline': '\x1b[26m', 'no-reverse': '\x1b[27m', 'no-standout': '\x1b[23m', 'no-underline': '\x1b[24m', 'normal': '\x1b[0m', 'overline': '\x1b[06m', 'purple': '\x1b[35m', 'red': '\x1b[31;01m', 'reset': '\x1b[39;49;00m', 'reverse': '\x1b[07m', 'standout': '\x1b[03m', 'teal': '\x1b[36m', 'turquoise': '\x1b[36;01m', 'underline': '\x1b[04m', 'white': '\x1b[37;01m', 'yellow': '\x1b[33;01m'}

Maps attribute name to ansi code.

portage.output.color(fg, bg='default', attr=['normal'])
portage.output.colorize(color_key, text)
portage.output.colormap()
class portage.output.create_color_func(color_key)

Bases: object

_color_key
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()