Esempio n. 1
0
    def output(self, text, header = "", footer = "", back = False,
            importance = 0, level = "info", count = [], percent = False):

        count_str = ""
        if self.progress:

            if count:
                count_str = "(%s/%s) " % (str(count[0]), str(count[1]),)
                cur_prog = float(count[0])/count[1]
                if importance == 0:
                    progress_text = decolorize(text)
                else:
                    progress_text = str(int(cur_prog * 100)) + "%"
                self.progress.set_progress(cur_prog, progress_text)

            if importance < 1:
                myfunc = self.progress.set_extraLabel
            elif importance == 1:
                myfunc = self.progress.set_subLabel
            elif importance > 1:
                myfunc = self.progress.set_mainLabel
            myfunc(count_str+decolorize(text))

        if not back and hasattr(self, 'progress_log'):

            def update_gui():
                if hasattr(self.progress_log, '__call__'):
                    self.progress_log(header+count_str+text+footer)
                return False
            gobject.timeout_add(0, update_gui)

        elif not back:
            print_generic(count_str+text)
Esempio n. 2
0
def print_table(entropy_client, lines_data,
                cell_spacing=2, cell_padding=0,
                side_color=darkgreen):
    """
    Print a table composed by len(lines_data[i]) columns and len(lines_data)
    rows.

    @param lines_data: list of row data
    @type lines_data: list
    @keyword cell_spacing: cell spacing
    @type cell_spacing: int
    @keyword cell_padding: cell padding
    @type cell_padding: int
    @keyword side_color: colorization callback function
    @type side_color: callable
    """
    column_sizes = {}
    padding_side = int((cell_padding / 2))
    col_n = 0
    for cols in lines_data:
        if not isinstance(cols, (list, tuple)):
            # can be a plain string
            continue
        col_n = 0
        for cell in cols:
            cell_len = len(" "*padding_side + decolorize(cell.split("\n")[0]) \
                 + " "*padding_side)
            cur_len = column_sizes.get(col_n)
            if cur_len is None:
                column_sizes[col_n] = cell_len
            elif cur_len < cell_len:
                column_sizes[col_n] = cell_len
            col_n += 1

    # now actually print
    if col_n > 0:
        column_sizes[col_n - 1] = 0
    for cols in lines_data:
        txt = side_color(">>") + "  "

        if isinstance(cols, (list, tuple)):
            col_n = 0
            for cell in cols:
                max_len = column_sizes[col_n]
                cell = " "*padding_side + cell + " "*padding_side
                delta_len = max_len - \
                    len(decolorize(cell.split("\n")[0])) + \
                    cell_spacing
                if col_n == (len(cols) - 1):
                    txt += cell
                else:
                    txt += cell + " "*delta_len
                col_n += 1
        else:
            txt += cols
        entropy_client.output(txt, level="generic")
Esempio n. 3
0
def print_table(entropy_client, lines_data,
                cell_spacing=2, cell_padding=0,
                side_color=darkgreen):
    """
    Print a table composed by len(lines_data[i]) columns and len(lines_data)
    rows.

    @param lines_data: list of row data
    @type lines_data: list
    @keyword cell_spacing: cell spacing
    @type cell_spacing: int
    @keyword cell_padding: cell padding
    @type cell_padding: int
    @keyword side_color: colorization callback function
    @type side_color: callable
    """
    column_sizes = {}
    padding_side = int((cell_padding / 2))
    col_n = 0
    for cols in lines_data:
        if not isinstance(cols, (list, tuple)):
            # can be a plain string
            continue
        col_n = 0
        for cell in cols:
            cell_len = len(" "*padding_side + decolorize(cell.split("\n")[0]) \
                 + " "*padding_side)
            cur_len = column_sizes.get(col_n)
            if cur_len is None:
                column_sizes[col_n] = cell_len
            elif cur_len < cell_len:
                column_sizes[col_n] = cell_len
            col_n += 1

    # now actually print
    if col_n > 0:
        column_sizes[col_n - 1] = 0
    for cols in lines_data:
        txt = side_color(MESSAGE_HEADER) + "  "

        if isinstance(cols, (list, tuple)):
            col_n = 0
            for cell in cols:
                max_len = column_sizes[col_n]
                cell = " "*padding_side + cell + " "*padding_side
                delta_len = max_len - \
                    len(decolorize(cell.split("\n")[0])) + \
                    cell_spacing
                if col_n == (len(cols) - 1):
                    txt += cell
                else:
                    txt += cell + " "*delta_len
                col_n += 1
        else:
            txt += cols
        entropy_client.output(txt, level="generic")
Esempio n. 4
0
    def _format_action(self, action):
        # determine the required width and the entry label
        help_position = min(self._action_max_length + 2,
                            self._max_help_position)
        help_width = self._width - help_position
        action_width = help_position - self._current_indent - 2
        orig_action_header = self._format_action_invocation(action)
        action_header = decolorize(orig_action_header)

        # ho nelp; start on same line and add a final newline
        if not action.help:
            tup = self._current_indent, '', action_header
            action_header = '%*s%s\n' % tup

        # short action name; start on the same line and pad two spaces
        elif len(action_header) <= action_width:
            tup = self._current_indent, '', action_width, action_header
            tup_str = '%*s%-*s  ' % tup
            action_header = self.__colors(tup_str, orig_action_header)
            indent_first = 0

        # long action name; start on the next line
        else:
            tup = self._current_indent, '', action_header
            tup_str = '%*s%-*s  ' % tup
            action_header = self.__colors(tup_str, orig_action_header)
            indent_first = help_position

        # collect the pieces of the action help
        parts = [action_header]

        # if there was help for the action, add lines of help text
        if action.help:
            orig_help_text = self._expand_help(action)
            help_text = decolorize(orig_help_text)
            help_lines = self._split_lines(help_text, help_width)
            orig_help_lines = self._split_lines(orig_help_text, help_width)
            tup_str = '%*s%s' % (indent_first, '', help_lines[0])
            parts.append(self.__colors(tup_str, orig_help_lines[0]) + "\n")
            for idx, line in enumerate(help_lines[1:]):
                tup_str = '%*s%s' % (help_position, '', line)
                parts.append(
                    self.__colors(tup_str, orig_help_lines[idx+1]) + "\n")

        # or add a newline if the description doesn't end with one
        elif not action_header.endswith('\n'):
            parts.append('\n')

        # if there are any sub-actions, add their help as well
        for subaction in self._iter_indented_subactions(action):
            parts.append(self._format_action(subaction))

        # return a single string
        return self._join_parts(parts)
Esempio n. 5
0
 def do_ask():
     choice = choiceDialog(parent, decolorize(question),
         _("Entropy needs your attention"),
         [_(x) for x in responses]
     )
     try:
         result = responses[choice]
     except IndexError:
         result = responses[0]
     self._mthread_rc['ask_question'][th_id] = result
Esempio n. 6
0
 def do_ask():
     result = inputDialog(parent, decolorize(title), input_parameters,
         cancel = cancel_button)
     self._mthread_rc['input_box'][th_id] = result