about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/etc/get-snapshot.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py
index 442c50ed773..432c6b24946 100755
--- a/src/etc/get-snapshot.py
+++ b/src/etc/get-snapshot.py
@@ -48,23 +48,27 @@ def unpack_snapshot(triple, dl_path):
 # The first is the O/S triple.
 # The second is an optional path to the snapshot to use.
 
-triple = sys.argv[1]
-if len(sys.argv) == 3:
-    dl_path = sys.argv[2]
-else:
-    snap = determine_curr_snapshot(triple)
-    dl = os.path.join(download_dir_base, snap)
-    url = download_url_base + "/" + snap
-    print("determined most recent snapshot: " + snap)
+def main(argv):
+    triple = argv[1]
+    if len(argv) == 3:
+        dl_path = argv[2]
+    else:
+        snap = determine_curr_snapshot(triple)
+        dl = os.path.join(download_dir_base, snap)
+        url = download_url_base + "/" + snap
+        print("determined most recent snapshot: " + snap)
 
-    if (not os.path.exists(dl)):
-        get_url_to_file(url, dl)
+        if (not os.path.exists(dl)):
+            get_url_to_file(url, dl)
 
-    if (snap_filename_hash_part(snap) == hash_file(dl)):
-        print("got download with ok hash")
-    else:
-        raise Exception("bad hash on download")
+        if (snap_filename_hash_part(snap) == hash_file(dl)):
+            print("got download with ok hash")
+        else:
+            raise Exception("bad hash on download")
+
+        dl_path = os.path.join(download_dir_base, snap)
 
-    dl_path = os.path.join(download_dir_base, snap)
+    unpack_snapshot(triple, dl_path)
 
-unpack_snapshot(triple, dl_path)
+if __name__ == '__main__':
+    main(sys.argv)