-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtio-win-updater.py
More file actions
63 lines (49 loc) · 2.27 KB
/
virtio-win-updater.py
File metadata and controls
63 lines (49 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
import argparse, sys, urllib, datetime
import urllib.request
CURRENT_PLATFORM = sys.platform.lower()
parser = argparse.ArgumentParser(prog="virtio-win-updater")
group = parser.add_mutually_exclusive_group()
parser.add_argument("-b", "--branch", type=str, help="Override the default branch",
default="stable", metavar="", required=False)
parser.add_argument("-d", "--download-directory", type=str, help="Override the default download path",
metavar="", required=True)
parser.add_argument("-v", "--verbose", action="store_true", help="Print more messages")
group.add_argument("--version", action="version", version="%(prog)s 1.0")
args = parser.parse_args()
def get_virtio_iso(destination_path: str, branch: str):
main_url: str = "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads"
time: str = "{:%Y%m%d_%H%M%S}".format(datetime.datetime.now())
if destination_path.endswith("/"):
destination_path = destination_path.removesuffix("/")
upstream_iso: str = f"{main_url}/{branch}-virtio/virtio-win.iso"
stable_iso: str = f"{destination_path}/virtio-win-stable_{time}.iso"
latest_iso: str = f"{destination_path}/virtio-win-latest_{time}.iso"
match branch:
case "stable":
print("Downloading file:", stable_iso)
try:
urllib.request.urlretrieve(upstream_iso, stable_iso)
except Exception as e:
raise e
case "latest":
print("Downloading file:", latest_iso)
try:
urllib.request.urlretrieve(upstream_iso, latest_iso)
except Exception as e:
raise e
case _:
if branch:
raise ValueError(f"{branch} is not a valid branch")
else:
raise ValueError(f"no valid branch was specified")
if __name__ == '__main__':
if not CURRENT_PLATFORM == "linux":
raise RuntimeError(f"{sys.platform.lower()}: platform not supported")
else:
try:
if args.download_directory.endswith("/"):
args.download_directory = args.download_directory.removesuffix("/")
get_virtio_iso(args.download_directory, args.branch)
except Exception as e:
raise e