Exemplo n.º 1
0
def get_cols():
    from tqdm._utils import _environ_cols_wrapper

    _get_cols = _environ_cols_wrapper()
    if _get_cols:
        return _get_cols(sys.stdout)
    return 50
Exemplo n.º 2
0
 def pause(self):
     """ Call `pause` if progress is running, hasn't finish, and
 you want to print something else on the scree.
 """
     # ====== clear the report ====== #
     if self._last_report is not None:
         nlines = len(self._last_report.split("\n"))
         self.__pb.moveto(-nlines)
         for i in range(nlines):
             Progbar.FP.write('\r')
             console_width = _environ_cols_wrapper()(Progbar.FP)
             Progbar.FP.write(
                 ' ' * (79 if console_width is None else console_width))
             Progbar.FP.write(
                 '\r')  # place cursor back at the beginning of line
             self.__pb.moveto(1)
     else:
         nlines = 0
     # ====== clear the bar ====== #
     if self.__pb is not None:
         self.__pb.clear()
         self.__pb.moveto(-nlines)
     # ====== reset the last report ====== #
     # because we already clean everything,
     # set _last_report=None prevent
     # further moveto(-nlines) in add()
     self._last_report = None
     return self
Exemplo n.º 3
0
 def _new_epoch(self):
     if self.__pb is None:
         return
     # calculate number of offset lines from last report
     if self._last_report is None:
         nlines = 0
     else:
         nlines = len(self._last_report.split('\n'))
     # ====== reset progress bar (tqdm) ====== #
     if self.__keep:  # keep the last progress on screen
         self.__pb.moveto(nlines)
     else:  # clear everything
         for i in range(nlines):
             Progbar.FP.write('\r')
             console_width = _environ_cols_wrapper()(Progbar.FP)
             Progbar.FP.write(
                 ' ' * (79 if console_width is None else console_width))
             Progbar.FP.write(
                 '\r')  # place cursor back at the beginning of line
             self.__pb.moveto(1)
         self.__pb.moveto(-(nlines * 2))
     self.__pb.close()
     # ====== create epoch summary ====== #
     for key, values in self._epoch_hist[self._epoch_idx].items():
         values = [v for v in values]
         # provided summarizer function
         if key in self._epoch_summarizer_func:
             self._epoch_summary[self._epoch_idx][
                 key] = self._epoch_summarizer_func[key](values)
         # very heuristic way to deal with sequence of numbers
         elif isinstance(values[0], Number):
             self._epoch_summary[self._epoch_idx][key] = np.mean(values)
         # numpy array
         elif isinstance(values[0], np.ndarray):
             self._epoch_summary[self._epoch_idx][key] = sum(
                 v for v in values)
     # total epoch time
     total_time = time.time() - self._epoch_start_time
     self._epoch_summary[self._epoch_idx]['__total_time__'] = total_time
     # average time for 1 object
     avg_time = self.__pb.avg_time
     if avg_time is None:
         avg_time = total_time / self.target
     self._epoch_summary[self._epoch_idx]['__avg_time__'] = avg_time
     # reset all flags
     self.__pb = None
     self._last_report = None
     self._last_print_time = None
     self._epoch_start_time = None
     self._epoch_idx += 1
     return self
Exemplo n.º 4
0
    def __init__(self, status_objs, delay_draw=0.2):
        """
        Represent status objects with a progress bars.

        Parameters
        ----------
        status_objs : list
            Status objects
        delay_draw : float, optional
            To avoid flashing progress bars that will complete quickly after
            they are displayed, delay drawing until the progress bar has been
            around for awhile. Default is 0.2 seconds.
        """
        self.meters = []
        self.status_objs = []
        # Determine terminal width.
        self.ncols = _environ_cols_wrapper()(sys.stdout) or 79
        self.fp = sys.stdout
        self.creation_time = time.time()
        self.delay_draw = delay_draw
        self.drawn = False
        self.done = False
        self.lock = threading.RLock()

        # If the ProgressBar is not finished before the delay_draw time but
        # never again updated after the delay_draw time, we need to draw it
        # once.
        if delay_draw:
            threading.Thread(target=self._ensure_draw, daemon=True).start()

        # Create a closure over self.update for each status object that
        # implemets the 'watch' method.
        for st in status_objs:
            with self.lock:
                if hasattr(st, 'watch') and not st.done:
                    pos = len(self.meters)
                    self.meters.append('')
                    self.status_objs.append(st)
                    st.watch(partial(self.update, pos))
Exemplo n.º 5
0
def console_width(minimum=None, default=80):
    "Return width of available window area."
    from tqdm._utils import _environ_cols_wrapper
    return max(minimum or 0, _environ_cols_wrapper()(sys.stdout) or default)
Exemplo n.º 6
0
def console_width(minimum=None, default=80):
    "Return width of available window area."
    from tqdm._utils import _environ_cols_wrapper
    return max(minimum or 0, _environ_cols_wrapper()(sys.stdout) or default)
Exemplo n.º 7
0
import pyalpm
import sys
import os
from tqdm import tqdm
from tqdm._utils import _environ_cols_wrapper
from eyapm import event

cols = _environ_cols_wrapper()(sys.stdout)

_last_operation_action = None

_current_operate_pkg_map = {}


def _start_operation_action(*args):
    event_str = args[1]
    global _last_operation_action
    if event_str.startswith('Adding'):
        _last_operation_action = 'installing'
    elif event_str.startswith('Upgrading'):
        _last_operation_action = 'upgrading'
    elif event_str.startswith('Reinstalling'):
        _last_operation_action = 'reinstalling'
    elif event_str.startswith('Downgrading'):
        _last_operation_action = 'downgrading'
    elif event_str.startswith('Removing'):
        _last_operation_action = 'removing'


def _start_check_keyring(*args):
Exemplo n.º 8
0
 def __init__(self):
     from tqdm._utils import _term_move_up, _environ_cols_wrapper
     self._r_prefix = _term_move_up() + '\r'
     self._dynamic_ncols = _environ_cols_wrapper()
Exemplo n.º 9
0
def TERM_WIDTH():
    if sys.stdout.isatty():
        return _environ_cols_wrapper()(sys.stdout)
    else:
        return 0