コード例 #1
0
def window_size_env_cmds():
    """Returns a sequence of `docker run` arguments that will internally configure
  the terminal columns and lines, so that progress bars and other terminal
  interactions will work properly.

  These aren't required for interactive Docker commands like those triggered by
  `caliban shell`.

  """
    ret = []
    cols, lines = _screen_shape_wrapper()(0)
    if cols:
        ret += ["-e", f"COLUMNS={cols}"]
    if lines:
        ret += ["-e", f"LINES={lines}"]
    return ret
コード例 #2
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 = _screen_shape_wrapper()(sys.stdout)[0] 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))
コード例 #3
0
except ImportError:
  tqdm = tqdm_std
else:
  tqdm_std.set_lock(RLock())
  tqdm = partial(tqdm_std, lock_args=(False,))

__author__ = "Casper da Costa-Luis <*****@*****.**>"
__date__ = "2016-2020"
__licence__ = "[MPLv2.0](https://mozilla.org/MPL/2.0/)"
__all__ = ["TERM_WIDTH", "int_cast_or_len", "Max", "fext", "_str", "tqdm",
           "tighten", "check_output", "print_unicode", "StringIO", "Str"]
__copyright__ = ' '.join(("Copyright (c)", __date__, __author__, __licence__))
__license__ = __licence__  # weird foreign language

log = logging.getLogger(__name__)
TERM_WIDTH = _screen_shape_wrapper()(sys.stdout)[0]
if not TERM_WIDTH:
  # non interactive pipe
  TERM_WIDTH = 256


class TqdmStream(object):
  @classmethod
  def write(cls, msg):
    tqdm_std.write(msg, end='')


def check_output(*a, **k):
  log.debug(' '.join(a[0][3:]))
  k.setdefault('stdout', subprocess.PIPE)
  return subprocess.Popen(*a, **k).communicate()[0].decode(
コード例 #4
0
def console_width(minimum=None, default=80):
    "Return width of available window area."
    from tqdm.utils import _screen_shape_wrapper
    x = _screen_shape_wrapper()(sys.stdout)[0]
    return max(minimum or 0, x or default)