def test_contextmanager(): f = FakeFile() with ui.ProgressBar(1024**3, output=f) as pb: pb.update(1024**3) assert f.last.endswith("\r") assert f.last.endswith("\n")
def download_disk(connection, backup_uuid, disk, disk_path, args): transfer = create_transfer(connection, backup_uuid, disk) try: # We must use the daemon for downloading a backup disk. download_url = transfer.transfer_url with ui.ProgressBar() as pb: client.download(download_url, disk_path, args.cafile, secure=args.secure, progress=pb) finally: finalize_transfer(connection, transfer)
def test_draw(monkeypatch): monkeypatch.setattr(ui, "time", FakeTime()) f = FakeFile() # Size is unknown at this point. pb = ui.ProgressBar(output=f, step=0.1) assert f.last == ( "[ ------- ] 0 bytes, 0.00 seconds, 0 bytes/s".ljust(79) + "\r") # Size was updated. ui.time.now += 0.1 pb.size = 3 * 1024**3 pb.update(0) assert f.last == ( "[ 0.00% ] 0 bytes, 0.10 seconds, 0 bytes/s".ljust(79) + "\r") # Write some data... ui.time.now += 1.0 pb.update(512 * 1024**2) assert f.last == ( "[ 16.67% ] 512.00 MiB, 1.10 seconds, 465.45 MiB/s".ljust(79) + "\r") # Write zeros, much faster, but it is not time to update yet... ui.time.now += 0.05 pb.update(512 * 1024**2) assert f.last == ( "[ 16.67% ] 512.00 MiB, 1.10 seconds, 465.45 MiB/s".ljust(79) + "\r") # Write more zeors, time to update... ui.time.now += 0.05 pb.update(512 * 1024**2) assert f.last == ( "[ 50.00% ] 1.50 GiB, 1.20 seconds, 1.25 GiB/s".ljust(79) + "\r") # More zeros, rates increases... ui.time.now += 0.1 pb.update(1024**3) assert f.last == ( "[ 83.33% ] 2.50 GiB, 1.30 seconds, 1.92 GiB/s".ljust(79) + "\r") # More data, slow down again... ui.time.now += 1.0 pb.update(512 * 1024**2) assert f.last == ( "[ 100.00% ] 3.00 GiB, 2.30 seconds, 1.30 GiB/s".ljust(79) + "\r") # Flush takes some time, lowering final rate. ui.time.now += 0.1 pb.close() assert f.last == ( "[ 100.00% ] 3.00 GiB, 2.40 seconds, 1.25 GiB/s".ljust(79) + "\n")
print("Transfer host: %s" % transfer_host.name) if args.use_proxy: download_url = transfer.proxy_url else: download_url = transfer.transfer_url # At this stage, the SDK granted the permission to start transferring the disk, and the # user should choose its preferred tool for doing it. We use the recommended # way, ovirt-imageio client library. print("Downloading image...") try: with ui.ProgressBar() as pb: client.download( download_url, args.filename, args.cafile, fmt=args.format, secure=args.secure, progress=pb) finally: # Finalize the session. print("Finalizing image transfer...") transfer_service.finalize() # Close the connection to the server: connection.close()