summarylogtreecommitdiffstats
path: root/pvm-wrapper.py
blob: aac15204d3723089c62106b46b36923aec556a93 (plain)
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
#!/usr/bin/env python3
import os, sys
from pathlib import Path
from urllib.request import urlopen

LOADER_URL = "https://raw.githubusercontent.com/f1nnsauce/pvm/refs/heads/main/loader.py"
LOADER_VERSION_URL = "https://raw.githubusercontent.com/f1nnsauce/pvm/refs/heads/main/pvm-version-loader.txt"

LOCAL_DIR = Path.home() / ".local/share/pvm"
LOCAL_DIR.mkdir(parents=True, exist_ok=True)
LOADER = LOCAL_DIR / "loader.py"
LOADER_VERSION = LOCAL_DIR / "pvm-version-loader.txt"

def fetch(url: str) -> str:
    with urlopen(url) as r:
        return r.read().decode("utf-8")

if len(sys.argv) == 2 and sys.argv[1] == "update":
    LOADER.write_text(fetch(LOADER_URL))
    LOADER_VERSION.write_text(fetch(LOADER_VERSION_URL))
    print("PVM Loader updated.")
    sys.exit(0)
if not LOADER.exists():
    LOADER.write_text(fetch(LOADER_URL))
if not LOADER_VERSION.exists():
    LOADER_VERSION.write_text(fetch(LOADER_VERSION_URL))

# Run the actual loader
os.execv(
    sys.executable,
    [sys.executable, str(LOADER), *sys.argv[1:]]
)