From db5218f7c05a97bf3ca523e45f15f29b6f952d2a Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Fri, 25 Sep 2015 13:24:08 +0200 Subject: [PATCH] Snapshotter show outputs ALL snapshots --- snapshotter.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/snapshotter.py b/snapshotter.py index ee842960..83a77416 100755 --- a/snapshotter.py +++ b/snapshotter.py @@ -91,19 +91,27 @@ def show(): vms = get_vagrant_vms() for vm in vms: msg = "[{vm}] {snap}" - kwargs = { - 'vm': click.style(vm, fg='green'), - 'snap': '', - } + click.echo(click.style(vm, fg='green')) try: snap = vboxmanage(['snapshot', vm, 'list'], output_dict=True) - kwargs['snap'] = '{SnapshotName} (UUID: {SnapshotUUID})'.format(**snap) + snap_num = (len(snap.keys()) / 3) - 1 + if snap_num < 1: + click.echo(click.style( + 'This machine does not have any snapshots', + fg='red' + )) + else: + s = {} + for key, value in snap.items(): + if not key.startswith('SnapshotName'): + continue + uuid_key = key.replace("SnapshotName", "SnapshotUUID") + click.echo('\t{name} (UUID {uuid})'.format(name=value, uuid=snap[uuid_key])) except CalledProcessError: - kwargs['snap'] = click.style( + click.echo(click.style( 'This machine does not have any snapshots', fg='red' - ) - click.echo(msg.format(**kwargs)) + )) click.echo('-' * 10)