-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmass_update.py
executable file
·67 lines (51 loc) · 1.98 KB
/
mass_update.py
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
64
65
66
67
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3 python3Packages.packaging
import asyncio
import re
import subprocess
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from shutil import copy
from tempfile import TemporaryDirectory
from packaging.version import Version
VERSION_REGEX = re.compile(r"[^-]*-(\d+\.\d+)\.zip")
executor = ThreadPoolExecutor(max_workers=1)
async def get_foundry_versions(path: Path):
"""
Copy the Foundry packages to a temporary location. This allows them to be kept
on a slower storage medium without slowing down the update process too much.
Callers are responsible for ensuring the returned path is cleaned up properly.
"""
versions = path.glob("FoundryVTT*.zip")
prev = None
for version in sorted(
versions, key=lambda path: Version(VERSION_REGEX.match(path.name).group(1))
):
next_tmpdir = TemporaryDirectory()
next_future = executor.submit(lambda: copy(version, next_tmpdir.name))
if prev:
future, tmpdir = prev
await asyncio.wrap_future(future)
yield tmpdir
prev = (next_future, next_tmpdir)
if prev:
future, tmpdir = prev
await asyncio.wrap_future(future)
yield tmpdir
async def main(args):
path = Path(args[1]).absolute()
update_script = Path(args[2]).absolute()
print("Updating FoundryVTT versions:")
print(f" Source Path: {path}")
print(f" Update Script: {update_script}")
async for version_path in get_foundry_versions(path):
with version_path:
foundryvtt_path = next(Path(version_path.name).iterdir())
print(f"Generating package-lock.json for {foundryvtt_path.name}")
subprocess.run([update_script, foundryvtt_path], capture_output=True)
print("Updates complete")
if __name__ == "__main__":
import asyncio
import sys
event_loop = asyncio.new_event_loop()
event_loop.run_until_complete(main(sys.argv))