Exemple #1
0
def enableProgressBar():
    global use_progress_bar  # singleton, pylint: disable=global-statement
    global tqdm  # singleton, pylint: disable=global-statement

    if isWin32Windows():
        colorama = importFromInlineCopy("colorama", must_exist=True)
        colorama.init()

    tqdm = importFromInlineCopy("tqdm", must_exist=False)

    if tqdm is None:
        try:
            # Cannot use import tqdm due to pylint bug.
            import tqdm as tqdm_installed  # pylint: disable=I0021,import-error

            tqdm = tqdm_installed
        except ImportError:
            # We handle the case without inline copy too, but it may be removed, e.g. on
            # Debian it's only a recommended install, and not included that way.
            pass

    # Tolerate the absence ignore the progress bar
    if tqdm is not None:
        tqdm = tqdm.tqdm

        tqdm.set_lock(RLock())
        use_progress_bar = True
Exemple #2
0
def _getTqdmModule():
    global tqdm  # singleton, pylint: disable=global-statement

    if tqdm:
        return tqdm
    elif tqdm is False:
        return None
    else:
        tqdm = importFromInlineCopy("tqdm", must_exist=False)

        if tqdm is None:
            try:
                # Cannot use import tqdm due to pylint bug.
                import tqdm as tqdm_installed  # pylint: disable=I0021,import-error

                tqdm = tqdm_installed
            except ImportError:
                # We handle the case without inline copy too, but it may be removed, e.g. on
                # Debian it's only a recommended install, and not included that way.
                pass

        if tqdm is None:
            tqdm = False
            return None

        tqdm = tqdm.tqdm

        # Tolerate the absence ignore the progress bar
        tqdm.set_lock(RLock())

        return tqdm
Exemple #3
0
""" Progress bars in Nuitka.

This is responsible for wrapping the rendering of progress bar and emitting tracing
to the user while it's being displayed.

"""

from nuitka import Tracing
from nuitka.utils.ThreadedExecutor import RLock

try:
    from tqdm import tqdm
except ImportError:
    tqdm = None
else:
    tqdm.set_lock(RLock())


class NuitkaProgessBar(object):
    def __init__(self, stage, total, unit):
        self.stage = stage
        self.total = total
        self.unit = unit

        # No item under work yet.
        self.item = None

        # No progress yet.
        self.progress = 0

        # Render immediately with 0 progress.
Exemple #4
0
        # Only necessary on Windows, as a side effect of this, ANSI colors get enabled
        # for the terminal and never deactivated, so we are free to use them after
        # this.
        if os.name == "nt":
            os.system("")

        _enabled_ansi = True


def getDisableStyleCode():
    return "\033[0m"


# Locking seems necessary to avoid colored output split up.
trace_lock = RLock()


@contextmanager
def withTraceLock():
    """ Hold a lock, so traces cannot be output at the same time mixing them up. """

    trace_lock.acquire()
    yield
    trace_lock.release()


def my_print(*args, **kwargs):
    """Make sure we flush after every print.

    Not even the "-u" option does more than that and this is easy enough.