Exemplo n.º 1
0
def progress_db(progress, start_time, last_bytes, read_bytes, total_bytes, rethink_uuid):
    """Callback to update the database with our status periodically.
    :param progress: Percentage of progress.
    :param start_time: Time object from the operation's initiation.
    :param read_bytes: Number of bytes read since the operation was begun.
    :param total_bytes: Number of bytes total before the operation is complete.
    """
    elapsed = time() - start_time  # How much time has elapsed since we started?
    eta = calc_finish(read_bytes, total_bytes, elapsed)  # Calculate time until complete
    bar = calc_bar(progress, 20)  # Calculate a progress bar

    # Format the data
    fmt_progress = "%3d%%" % progress
    time_elapsed = "%02ld:%02ld:%02ld" % (elapsed / 3600, (elapsed / 60) % 60, elapsed % 60)
    time_remaining = "%02ld:%02ld:%02ld" % (eta / 3600, (eta / 60) % 60, eta % 60)
    read_megs = (read_bytes / (1024 * 1024))
    total_megs = (total_bytes / (1024 * 1024))
    speed_bytes = read_bytes - last_bytes
    speed_megs = (speed_bytes / (1024 * 1024))

    # Insert Data
    # noinspection PyUnusedLocal
    updated = r.db('wanwipe').table('wipe_results').get(rethink_uuid).update({
        'progress': fmt_progress,
        'progress_bar': bar,
        'updated_at': r.now(),
        'time_elapsed': time_elapsed,
        'time_remaining': time_remaining,
        'speed_megs': speed_megs,
        'speed_bytes': speed_bytes,
        'read_megs': read_megs,
        'read_bytes': read_bytes
    }).run(conn)
    # Print the collected information to stdout. Should barely fit in 80-column.

    sys.stdout.write("\r{}  {}  [{}]  ETA {} {}/{}M {}M/s  \b\b".format(
        fmt_progress, time_elapsed, bar, time_remaining, read_megs, total_megs, speed_megs))
    sys.stdout.flush()  # Flush the stdout buffer to the screen.
Exemplo n.º 2
0
def progress(progress, start_time, last_bytes, read_bytes, total_bytes, rethink_uuid=None):
    """Callback to display a graphical callback bar. Optional.
    :param progress: Percentage of progress.
    :param start_time: Time object from the operation's initiation.
    :param read_bytes: Number of bytes read since the operation was begun.
    :param total_bytes: Number of bytes total before the operation is complete.
    """
    elapsed = time() - start_time  # How much time has elapsed since we started?
    eta = calc_finish(read_bytes, total_bytes, elapsed)  # Calculate time until complete
    bar = calc_bar(progress, 20)  # Calculate a progress bar

    # Format the data
    fmt_progress = "%3d%%" % progress
    time_elapsed = "%02ld:%02ld:%02ld" % (elapsed / 3600, (elapsed / 60) % 60, elapsed % 60)
    time_remaining = "%02ld:%02ld:%02ld" % (eta / 3600, (eta / 60) % 60, eta % 60)
    read_megs = (read_bytes / (1024 * 1024))
    total_megs = (total_bytes / (1024 * 1024))
    speed_bytes = read_bytes - last_bytes
    speed_megs = (speed_bytes / (1024 * 1024))

    # Print the collected information to stdout. Should barely fit in 80-column.
    sys.stdout.write("\r{}  {}  [{}]  ETA {} {}/{}M {}M/s  \b\b".format(
        fmt_progress, time_elapsed, bar, time_remaining, read_megs, total_megs, speed_megs))
    sys.stdout.flush()  # Flush the stdout buffer to the screen.