Ejemplo n.º 1
0
def example12():
    widgets = ['Balloon: ', AnimatedMarker(markers='.oO@* ')]
    pbar = ProgressBar(widgets=widgets)
    for i in range(24):
        time.sleep(0.01)
        pbar.update(i + 1)
    pbar.finish()
Ejemplo n.º 2
0
def Cmc(q_data, g_data, rank_size):
    n_query = q_data['feature'].shape[0]
    n_gallery = g_data['feature'].shape[0]

    dist = np_cdist(q_data['feature'],
                    g_data['feature'])  # Reture a n_query*n_gallery array

    cmc = np.zeros((n_query, rank_size))
    ap = np.zeros(n_query)

    widgets = [
        "I'm calculating cmc! ",
        AnimatedMarker(markers='←↖↑↗→↘↓↙'), ' (',
        Percentage(), ')'
    ]
    pbar = ProgressBar(widgets=widgets, max_value=n_query)
    for k in range(n_query):
        good_idx = np.where((q_data['id'][k] == g_data['id'])
                            & (q_data['cam'][k] != g_data['cam']))[0]
        junk_mask1 = (g_data['id'] == -1)
        junk_mask2 = (q_data['id'][k] == g_data['id']) & (q_data['cam'][k]
                                                          == g_data['cam'])
        junk_idx = np.where(junk_mask1 | junk_mask2)[0]
        score = dist[k, :]
        sort_idx = np.argsort(score)
        sort_idx = sort_idx[:rank_size]

        ap[k], cmc[k, :] = Compute_AP(good_idx, junk_idx, sort_idx)
        pbar.update(k)
    pbar.finish()
    CMC = np.mean(cmc, axis=0)
    mAP = np.mean(ap)
    return CMC, mAP
Ejemplo n.º 3
0
    def __init__(self, interface_type, count=None, description=None):
        self.interface_type = interface_type
        self.current_value = 0

        if self.interface_type == Config.UI_CLI:
            widgets = []

            if description is not None:
                widgets.append('{}: '.format(description))

            if count is not None:
                widgets.append(Percentage())
                widgets.append(' ')
                widgets.append(Bar())
            else:
                widgets.append(Counter())
                widgets.append(' ')
                widgets.append(AnimatedMarker(markers='.oO@* '))

            if count is not None:
                self.progressBar = ProgressBar(widgets=widgets,
                                               max_value=count)
            else:
                self.progressBar = ProgressBar(
                    max_value=progressbar.UnknownLength, widgets=widgets)
        else:
            PROGRESS_LOGGER.error('interface type not handled: {}'.format(
                self.interface_type))
            raise Exception('interface type not handled: {}'.format(
                self.interface_type))
Ejemplo n.º 4
0
def EvaluateGenomeList_Parallel(genome_list, evaluator, cores=4, display=True):
    fitnesses = []
    pool = mpc.Pool(processes=cores)
    curtime = time.time()

    if prbar_installed and display:
        widg = ['Individuals: ', Counter(),
                ' of ' + str(len(genome_list)), ' ', ETA(), ' ',
                AnimatedMarker()]
        progress = ProgressBar(maxval=len(genome_list), widgets=widg).start()

    for i, fitness in enumerate(pool.imap(evaluator, genome_list)):
        if prbar_installed and display:
            progress.update(i)
        else:
            if display:
                print 'Individuals: (%s/%s)' % (i, len(genome_list))

        if cvnumpy_installed:
            cv2.waitKey(1)
        fitnesses.append(fitness)

    if prbar_installed and display:
        progress.finish()

    elapsed = time.time() - curtime

    if display:
        print 'seconds elapsed: %s' % elapsed

    pool.close()
    pool.join()

    return fitnesses
Ejemplo n.º 5
0
def crack_password(hash_password, dictionary):
    """Compare hashed_password with dictionary of passwords

    These words a dictionary words plus some of the most common passwords
    captured from rockyou and websters-dictionary. No string manipulation occured.
    Only for words matching the simplest regular expression.

    Returns:
        If identified returns the plaintext word for the hash else, not found.
    """
    widgets = [
        'Attempting to crack password ',
        AnimatedMarker(), ' ',
        Percentage()
    ]
    pbar = ProgressBar(widgets=widgets, maxval=len(dictionary)).start()
    i = 0
    for word in dictionary:
        if check_password(word, hash_password):
            pbar.finish()
            print "Password identified, password ===> " + word
            return
        i += 1
        pbar.update(i)
    pbar.finish()
    print "Failed : Password not identified"
Ejemplo n.º 6
0
def infinite_progress(name=None, status=False):
    widgets = defaut_widgets(name, status)
    widgets.extend(Counter(), " ", AnimatedMarker())

    progress = MyProgressBar(widgets=widgets)
    progress.status = status
    return progress
Ejemplo n.º 7
0
    def track(self):
        queue = Queue()
        thread = Thread(target=self._update_status, args=(queue,))
        thread.start()

        widgets = ["Processing...", AnimatedMarker()]
        progress_indicator = ProgressBar(widgets=widgets, maxval=UnknownLength)
        progress_indicator.start()

        content = {}
        for indicator_count in itertools.count():
            progress_indicator.update(indicator_count)
            if not queue.empty():
                content = queue.get()
                if isinstance(content, Exception):
                    raise content
            if content.get("processed"):
                break
            else:
                widgets[0] = self._get_message(content)
            sleep(0.1)
        progress_indicator.finish()
        # Print at the end to avoid a left over spinner artifact
        print(self._get_message(content))

        self.__content = content

        return content
Ejemplo n.º 8
0
def new_world(save=True, notify=True):
    logging.debug('Generating new world')
    world = GameWorld()

    world_hook.run(True, world)

    worldfile = open('world.dat', 'wb')
    if save:
        if notify:
            pbar = ProgressBar(widgets=['Saving: ',
                                        AnimatedMarker()],
                               maxval=600).start()
        savethread = threading.Thread(
            target=pickle.dump,
            args=(world, worldfile),
            kwargs={'protocol': pickle.HIGHEST_PROTOCOL})
        savethread.start()
        i = 0
        while savethread.isAlive():
            pbar.update(i)
            i += 1 if i != 600 else -599
            time.sleep(0.1)

    worldfile.close()
    return world
Ejemplo n.º 9
0
def download_requests_stream(request_stream, destination, message=None):
    """ This is a facility to download a request with nice progress bars.
    """
    if not message:
        message = 'Downloading {!r}'.format(os.path.basename(destination))

    total_length = int(request_stream.headers.get('Content-Length', '0'))
    if total_length:
        progress_bar = ProgressBar(
            widgets=[message,
                     Bar(marker='=', left='[', right=']'),
                     ' ', Percentage()],
            maxval=total_length)
    else:
        progress_bar = ProgressBar(
            widgets=[message, AnimatedMarker()],
            maxval=UnknownLength)

    total_read = 0
    progress_bar.start()
    with open(destination, 'wb') as destination_file:
        for buf in request_stream.iter_content(1024):
            destination_file.write(buf)
            total_read += len(buf)
            try:
                progress_bar.update(total_read)
            except ValueError as e:
                app.log.exception(
                    "Failed on total_read({}) "
                    "is not between 0-100: {}".format(total_read, e))
    progress_bar.finish()
Ejemplo n.º 10
0
def EvaluateGenomeList_Serial(genome_list, evaluator, display=True):
    fitnesses = []
    count = 0

    if prbar_installed and display:
        widg = ['Individuals: ', Counter(), ' of ' + str(len(genome_list)),
                ' ', ETA(), ' ', AnimatedMarker()]
        progress = ProgressBar(maxval=len(genome_list), widgets=widg).start()

    for g in genome_list:
        f = evaluator(g)
        fitnesses.append(f)

        if display:
            if prbar_installed:
                progress.update(count+1)
            else:
                print 'Individuals: (%s/%s)' % (count, len(genome_list))
        
                count += 1

    if prbar_installed and display:
        progress.finish()

    return fitnesses
Ejemplo n.º 11
0
def EvaluateGenomeList_Serial(genome_list, evaluator):
    fitnesses = []
    curtime = time.time()

    if prbar_installed:
        widg = ['Individuals: ', Counter(), ' of ' + str(len(genome_list)),
                ' ', ETA(), ' ', AnimatedMarker()]
        progress = ProgressBar(maxval=len(genome_list), widgets=widg).start()

    count = 0
    for g in genome_list:
        f = evaluator(g)
        fitnesses.append(f)

        if prbar_installed:
            progress.update(count)
        else:
            print 'Individuals: (%s/%s)' % (count, len(genome_list))

        count += 1

    if prbar_installed:
        progress.finish()

    elapsed = time.time() - curtime
    print 'seconds elapsed: %s' % elapsed
    return (fitnesses, elapsed)
Ejemplo n.º 12
0
    def track(self):
        queue = Queue()
        thread = Thread(target=self._update_status, args=(queue,))
        thread.start()

        widgets = ['Processing...', AnimatedMarker()]
        progress_indicator = ProgressBar(widgets=widgets, maxval=UnknownLength)
        progress_indicator.start()

        content = {}
        for indicator_count in itertools.count():
            if not queue.empty():
                content = queue.get()
                if isinstance(content, Exception):
                    raise content
                widgets[0] = self._get_message(content)
            progress_indicator.update(indicator_count)
            if content.get('processed'):
                break
            sleep(0.1)
        progress_indicator.finish()

        self.__content = content

        return content
Ejemplo n.º 13
0
def snap(project_options, directory=None, output=None):
    if directory:
        prime_dir = os.path.abspath(directory)
        snap = _snap_data_from_dir(prime_dir)
    else:
        # make sure the full lifecycle is executed
        prime_dir = project_options.prime_dir
        execute('prime', project_options)
        snap = _snap_data_from_dir(prime_dir)

    snap_name = output or common.format_snap_name(snap)

    # If a .snap-build exists at this point, when we are about to override
    # the snap blob, it is stale. We rename it so user have a chance to
    # recover accidentally lost assertions.
    snap_build = snap_name + '-build'
    if os.path.isfile(snap_build):
        _new = '{}.{}'.format(snap_build, int(time.time()))
        logger.warning('Renaming stale build assertion to {}'.format(_new))
        os.rename(snap_build, _new)

    # These options need to match the review tools:
    # http://bazaar.launchpad.net/~click-reviewers/click-reviewers-tools/trunk/view/head:/clickreviews/common.py#L38
    mksquashfs_args = ['-noappend', '-comp', 'xz', '-no-xattrs']
    if snap['type'] != 'os':
        mksquashfs_args.append('-all-root')

    with Popen(['mksquashfs', prime_dir, snap_name] + mksquashfs_args,
               stdout=PIPE,
               stderr=STDOUT) as proc:
        ret = None
        if is_dumb_terminal():
            logger.info('Snapping {!r} ...'.format(snap['name']))
            ret = proc.wait()
        else:
            message = '\033[0;32m\rSnapping {!r}\033[0;32m '.format(
                snap['name'])
            progress_indicator = ProgressBar(
                widgets=[message, AnimatedMarker()], maxval=7)
            progress_indicator.start()

            ret = proc.poll()
            count = 0

            while ret is None:
                if count >= 7:
                    progress_indicator.start()
                    count = 0
                progress_indicator.update(count)
                count += 1
                time.sleep(.2)
                ret = proc.poll()
        print('')
        if ret != 0:
            logger.error(proc.stdout.read().decode('utf-8'))
            raise RuntimeError('Failed to create snap {!r}'.format(snap_name))

        logger.debug(proc.stdout.read().decode('utf-8'))

    return snap_name
Ejemplo n.º 14
0
def example15():
    # You may need python 3.x to see this correctly
    try:
        widgets = ['Wheels: ', AnimatedMarker(markers='◐◓◑◒')]
        pbar = ProgressBar(widgets=widgets)
        for i in pbar((i for i in range(24))):
            time.sleep(0.3)
    except UnicodeError: sys.stdout.write('Unicode error: skipping example')
Ejemplo n.º 15
0
def example14():
    # You may need python 3.x to see this correctly
    try:
        widgets = ['Arrows: ', AnimatedMarker(markers='◢◣◤◥')]
        pbar = ProgressBar(widgets=widgets)
        for i in range(24):
            time.sleep(0.01)
            pbar.update(i + 1)
        pbar.finish()
    except UnicodeError:
        sys.stdout.write('Unicode error: skipping example')
Ejemplo n.º 16
0
class ProgressBarConfig:
    """
    Stores the config of the progress bar used for various time consuming computations.
    """
    widget = [
        AnimatedMarker(markers='◐◓◑◒'), ' ',
        ETA(), ' ',
        Percentage(), ' ',
        Bar(marker='=', left='[', right=']', fill='-')
    ]

    progress_bar = ProgressBar(widgets=widget)
Ejemplo n.º 17
0
def together(interval=10000):
    things = [
        AnimatedMarker(), " ",
        Counter(), "/{} ".format(interval),
        Percentage(), ' ',
        Speed(), ' ',
        Bar(), ' ',
        Timer(), ' ',
        ETA()
    ]
    pbar = ProgressBar(widgets=things, maxval=interval).start()
    for i in range(interval):
        pbar.update(i + 1)
    pbar.finish()
Ejemplo n.º 18
0
def snap(project_options, directory=None, output=None):
    if directory:
        snap_dir = os.path.abspath(directory)
        snap = _snap_data_from_dir(snap_dir)
    else:
        # make sure the full lifecycle is executed
        snap_dir = project_options.snap_dir
        snap = execute('prime', project_options)

    snap_name = output or common.format_snap_name(snap)

    # These options need to match the review tools:
    # http://bazaar.launchpad.net/~click-reviewers/click-reviewers-tools/trunk/view/head:/clickreviews/common.py#L38
    mksquashfs_args = ['-noappend', '-comp', 'xz', '-no-xattrs']
    if snap['type'] != 'os':
        mksquashfs_args.append('-all-root')

    with Popen(['mksquashfs', snap_dir, snap_name] + mksquashfs_args,
               stdout=PIPE,
               stderr=STDOUT) as proc:
        ret = None
        if os.isatty(sys.stdout.fileno()):
            message = '\033[0;32m\rSnapping {!r}\033[0;32m '.format(
                snap['name'])
            progress_indicator = ProgressBar(
                widgets=[message, AnimatedMarker()], maxval=7)
            progress_indicator.start()

            ret = proc.poll()
            count = 0

            while ret is None:
                if count >= 7:
                    progress_indicator.start()
                    count = 0
                progress_indicator.update(count)
                count += 1
                time.sleep(.2)
                ret = proc.poll()
        else:
            logger.info('Snapping {!r} ...'.format(snap['name']))
            ret = proc.wait()
        print('')
        if ret != 0:
            logger.error(proc.stdout.read().decode('utf-8'))
            raise RuntimeError('Failed to create snap {!r}'.format(snap_name))

        logger.debug(proc.stdout.read().decode('utf-8'))

    logger.info('Snapped {}'.format(snap_name))
Ejemplo n.º 19
0
def _run_mksquashfs(
    mksquashfs_command, *, directory, snap_name, snap_type, output_snap_name
):
    # These options need to match the review tools:
    # http://bazaar.launchpad.net/~click-reviewers/click-reviewers-tools/trunk/view/head:/clickreviews/common.py#L38
    mksquashfs_args = ["-noappend", "-comp", "xz", "-no-xattrs", "-no-fragments"]
    if snap_type != "base":
        mksquashfs_args.append("-all-root")

    complete_command = [
        mksquashfs_command,
        directory,
        output_snap_name,
    ] + mksquashfs_args

    with Popen(complete_command, stdout=PIPE, stderr=STDOUT) as proc:
        ret = None
        if is_dumb_terminal():
            logger.info("Snapping {!r} ...".format(snap_name))
            ret = proc.wait()
        else:
            message = "\033[0;32m\rSnapping {!r}\033[0;32m ".format(snap_name)
            progress_indicator = ProgressBar(
                widgets=[message, AnimatedMarker()], maxval=7
            )
            progress_indicator.start()

            ret = proc.poll()
            count = 0

            while ret is None:
                if count >= 7:
                    progress_indicator.start()
                    count = 0
                progress_indicator.update(count)
                count += 1
                time.sleep(0.2)
                ret = proc.poll()
        print("")
        output = proc.stdout.read().decode("utf-8")
        logger.debug(output)

        if ret != 0:
            raise RuntimeError(
                "Failed to create snap {!r}, mksquashfs failed:\n{}".format(
                    output_snap_name, output
                )
            )
Ejemplo n.º 20
0
def count_files(top, follow_links=False, progress=False):
    num_files = 0
    if progress:
        from progressbar import (
            ProgressBar, UnknownLength,
            AnimatedMarker, BouncingBar, Counter, Timer)
        widgets = [
            AnimatedMarker(), ' ',
            Counter('%(value)d files found'), ' ',
            BouncingBar(), ' ',
            Timer()]
        with ProgressBar(max_value=UnknownLength, widgets=widgets) as progress:
            for _, _, files in os.walk(top, followlinks=follow_links):
                num_files = num_files + len(files)
                progress.update(num_files)
    else:
        for _, _, files in os.walk(top, followlinks=follow_links):
            num_files = num_files + len(files)
    return num_files
Ejemplo n.º 21
0
def _update_progress(shared: Array, N: int) -> None:
    pbar_widgets = [
        f"{Fore.GREEN}Computing level variance: {Fore.RESET}",
        f"{Fore.BLUE}",
        Percentage(),
        f" {Fore.RESET}",
        " ",
        Timer(),
        f" {Fore.YELLOW}",
        AnimatedMarker(),
        f"{Fore.RESET}",
    ]
    pbar = ProgressBar(widgets=pbar_widgets, maxval=N).start()
    progress = np.frombuffer(shared.get_obj())
    done = int(progress[0])
    while done < N:  # type: ignore
        done = int(progress[0])
        pbar.update(done)
    pbar.finish()
Ejemplo n.º 22
0
def _run_mksquashfs(mksquashfs_command, *, directory, snap_name, snap_type,
                    output_snap_name):
    # These options need to match the review tools:
    # http://bazaar.launchpad.net/~click-reviewers/click-reviewers-tools/trunk/view/head:/clickreviews/common.py#L38
    mksquashfs_args = ['-noappend', '-comp', 'xz', '-no-xattrs',
                       '-no-fragments']
    if snap_type != 'os':
        mksquashfs_args.append('-all-root')

    complete_command = [
        mksquashfs_command, directory, output_snap_name] + mksquashfs_args

    with Popen(complete_command, stdout=PIPE, stderr=STDOUT) as proc:
        ret = None
        if is_dumb_terminal():
            logger.info('Snapping {!r} ...'.format(snap_name))
            ret = proc.wait()
        else:
            message = '\033[0;32m\rSnapping {!r}\033[0;32m '.format(
                snap_name)
            progress_indicator = ProgressBar(
                widgets=[message, AnimatedMarker()], maxval=7)
            progress_indicator.start()

            ret = proc.poll()
            count = 0

            while ret is None:
                if count >= 7:
                    progress_indicator.start()
                    count = 0
                progress_indicator.update(count)
                count += 1
                time.sleep(.2)
                ret = proc.poll()
        print('')
        if ret != 0:
            logger.error(proc.stdout.read().decode('utf-8'))
            raise RuntimeError('Failed to create snap {!r}'.format(
                output_snap_name))

        logger.debug(proc.stdout.read().decode('utf-8'))
Ejemplo n.º 23
0
    def test_xdelta3_with_progress_indicator(self):
        self.generate_snap_pair()
        base_delta = deltas.XDelta3Generator(source_path=self.source_file,
                                             target_path=self.target_file)

        message = "creating delta file from {!r}...".format(self.source_file)
        maxval = 10
        progress_indicator = ProgressBar(widgets=[message,
                                                  AnimatedMarker()],
                                         maxval=maxval)
        progress_indicator.start()

        path = base_delta.make_delta(progress_indicator=progress_indicator,
                                     is_for_test=True)
        progress_indicator.finish()

        self.assertThat(path, m.FileExists())
        expect_path = "{}.{}".format(base_delta.target_path,
                                     base_delta.delta_file_extname)
        self.assertThat(path, m.Equals(expect_path))
Ejemplo n.º 24
0
def _init_progress_bar(total_length, destination, message=None):
    if not message:
        message = "Downloading {!r}".format(os.path.basename(destination))

    valid_length = total_length and total_length > 0

    if valid_length and is_dumb_terminal():
        widgets = [message, " ", Percentage()]
        maxval = total_length
    elif valid_length and not is_dumb_terminal():
        widgets = [message, Bar(marker="=", left="[", right="]"), " ", Percentage()]
        maxval = total_length
    elif not valid_length and is_dumb_terminal():
        widgets = [message]
        maxval = UnknownLength
    else:
        widgets = [message, AnimatedMarker()]
        maxval = UnknownLength

    return ProgressBar(widgets=widgets, maxval=maxval)
Ejemplo n.º 25
0
def Cmc(q_data, g_data, rank_size):
    n_query = g_data['feature'].shape[0]
    n_gallery = g_data['feature'].shape[0]

    dist = np_cdist(g_data['feature'],
                    g_data['feature'])  # Reture a n_query*n_gallery array

    cmc = np.zeros((n_query, rank_size))
    ap = np.zeros(n_query)

    widgets = [
        "I'm calculating cmc! ",
        AnimatedMarker(markers='←↖↑↗→↘↓↙'), ' (',
        Percentage(), ')'
    ]
    pbar = tqdm(total=n_query, ncols=100, leave=True)
    for k in range(n_query):
        #        good_idx = np.where((q_data['id'][k]==g_data['id']) & (q_data['cam'][k]!=g_data['cam']))[0]
        #        good_idx = np.where((q_data['id'][k]==g_data['id']))[0]
        good_mask = (g_data['id'][k] == g_data['id'])
        good_mask[k] = 0
        good_idx = np.where(good_mask)[0]
        junk_mask1 = (g_data['id'] == -1)
        junk_mask1[k] = 1
        #        junk_mask2 = (q_data['id'][k]==g_data['id']) & (q_data['cam'][k]==g_data['cam'])
        #        junk_idx = np.where(junk_mask1 | junk_mask2)[0]
        junk_idx = np.where(junk_mask1)[0]
        score = dist[k, :]
        sort_idx = np.argsort(score)
        sort_idx = sort_idx[:rank_size]
        #        print(good_idx)
        #        print(sort_idx[:20])
        ap[k], cmc[k, :] = Compute_AP(good_idx, junk_idx, sort_idx)
        pbar.update(k)
    #pbar.finish()
    eff_num = np.sum(ap > -1)
    CMC = np.sum(cmc, axis=0) / eff_num
    mAP = np.mean(ap[ap > -1])
    return CMC, mAP
Ejemplo n.º 26
0
def download_requests_stream(request_stream, destination, message=None):
    """This is a facility to download a request with nice progress bars."""
    if not message:
        message = 'Downloading {!r}'.format(os.path.basename(destination))

    # Doing len(request_stream.content) may defeat the purpose of a
    # progress bar
    total_length = 0
    if not request_stream.headers.get('Content-Encoding', ''):
        total_length = int(request_stream.headers.get('Content-Length', '0'))

    if total_length and is_dumb_terminal():
        widgets = [message, ' ', Percentage()]
        maxval = total_length
    elif total_length and not is_dumb_terminal():
        widgets = [
            message,
            Bar(marker='=', left='[', right=']'), ' ',
            Percentage()
        ]
        maxval = total_length
    elif not total_length and is_dumb_terminal():
        widgets = [message]
        maxval = UnknownLength
    else:
        widgets = [message, AnimatedMarker()]
        maxval = UnknownLength

    progress_bar = ProgressBar(widgets=widgets, maxval=maxval)

    total_read = 0
    progress_bar.start()
    with open(destination, 'wb') as destination_file:
        for buf in request_stream.iter_content(1024):
            destination_file.write(buf)
            total_read += len(buf)
            progress_bar.update(total_read)
    progress_bar.finish()
Ejemplo n.º 27
0
def example12():
    widgets = ['Balloon: ', AnimatedMarker(markers='.oO@* ')]
    pbar = ProgressBar(widgets=widgets)
    for i in pbar((i for i in range(24))):
        time.sleep(0.3)
Ejemplo n.º 28
0
def example9():
    pbar = ProgressBar(widgets=['Working: ', AnimatedMarker()])
    for i in pbar((i for i in range(50))):
        time.sleep(.08)
Ejemplo n.º 29
0
@asyncio.coroutine
def _unarmor(a, future):
    b = yield from asyncio.get_event_loop().run_in_executor(None, pgpy.types.Exportable.ascii_unarmor, a)
    future.set_result(b)

_b = bytearray()


loop = asyncio.get_event_loop()
for ascfile in ascfiles:
    ascfile = os.path.abspath(ascfile)
    if not os.path.isfile(ascfile):
        sys.stderr.write('Error: {} does not exist'.format(ascfile))
        continue

    load_bar = ProgressBar(widgets=["Reading {} ({}): ".format(ascfile, Mebibyte(os.path.getsize(ascfile))), AnimatedMarker()])
    unarmor_bar = ProgressBar(widgets=["Unarmoring data: ", AnimatedMarker()])


    a = asyncio.Future()
    b = asyncio.Future()

    lbp = asyncio.Task(_dospinner(load_bar))
    asyncio.Task(_load_pubring(ascfile, a))
    loop.run_until_complete(a)
    _a = a.result()
    lbp.cancel()

    uap = asyncio.Task(_dospinner(unarmor_bar))
    asyncio.Task(_unarmor(_a, b))
    loop.run_until_complete(b)
Ejemplo n.º 30
0
    def wait(self, timeout=None, live_progress=False):
        """Wait for this task until it is completed.

        :param float timeout: maximum time (in seconds) to wait before returning
           (None => no timeout)
        :param bool live_progress: display a live progress

        :rtype: :class:`bool`
        :returns: Is the task finished

        :raises qarnot.exceptions.QarnotGenericException: API general error, see message for details
        :raises qarnot.exceptions.UnauthorizedException: invalid credentials
        :raises qarnot.exceptions.MissingTaskException: task does not represent a valid
          one
        """

        live_progress = live_progress and sys.stdout.isatty()

        if live_progress:
            try:
                widgets = [
                    Percentage(), ' ',
                    AnimatedMarker(), ' ',
                    Bar(), ' ',
                    AdaptiveETA()
                ]
                progressbar = ProgressBar(widgets=widgets, max_value=100)
            except Exception:
                live_progress = False

        start = time.time()
        if self._uuid is None:
            self.update(True)
            return False

        nap = min(10, timeout) if timeout is not None else 10

        self.update(True)
        while self._state in RUNNING_DOWNLOADING_STATES:
            if live_progress:
                n = 0
                progress = 0
                while True:
                    time.sleep(1)
                    n += 1
                    if n >= nap:
                        break
                    progress = self.status.execution_progress if self.status is not None else 0
                    progress = max(0, min(progress, 100))
                    progressbar.update(progress)
            else:
                time.sleep(nap)

            self.update(True)

            if timeout is not None:
                elapsed = time.time() - start
                if timeout <= elapsed:
                    self.update()
                    return False
                else:
                    nap = min(10, timeout - elapsed)
        self.update(True)
        if live_progress:
            progressbar.finish()
        return True