-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetch.py
More file actions
executable file
·106 lines (84 loc) · 3.13 KB
/
fetch.py
File metadata and controls
executable file
·106 lines (84 loc) · 3.13 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
######################################################################
# @author : Ruan E. Formigoni (ruanformigoni@gmail.com)
# @file : fetch
# @description : Generate fetch JSON from dist directory
######################################################################
import json
import sys
import re
from pathlib import Path
from collections import defaultdict
from urllib.request import urlopen
from urllib.error import URLError
def fetch_retroarch_cores():
"""Fetch the list of RetroArch cores from buildbot."""
url = "http://buildbot.libretro.com/nightly/linux/x86_64/latest/"
try:
with urlopen(url) as response:
html = response.read().decode('utf-8')
# Extract .so.zip files using regex
# Pattern matches: href=".*?latest/(.*?\.so.zip)"
pattern = r'href=".*?latest/(.*?\.so\.zip)"'
matches = re.findall(pattern, html, re.IGNORECASE)
# Remove duplicates and sort
core_files = sorted(set(matches))
return {
"url": url,
"files": core_files
}
except URLError as e:
print(f"Warning: Failed to fetch RetroArch cores from {url}: {e}", file=sys.stderr)
return None
def main():
if len(sys.argv) != 2:
print("Usage: fetch.sh <version>")
print("Example: fetch.sh gameimage-2.0.x")
sys.exit(1)
version = sys.argv[1]
script_dir = Path(__file__).parent
dist_dir = script_dir / "dist"
if not dist_dir.exists():
print(f"Error: dist directory not found at {dist_dir}")
sys.exit(1)
result = {}
# Parse layer files from dist directory
# Structure: platforms[platform][owner][repo][distribution][channel] = [versions]
platforms = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list)))))
for layer_file in dist_dir.glob("*.layer"):
filename = layer_file.stem
parts = filename.split("--")
if len(parts) != 6:
print(f"Warning: Unexpected layer format: {filename}", file=sys.stderr)
continue
platform, owner, repo, distribution, channel, version_str = parts
platforms[platform][owner][repo][distribution][channel].append(version_str)
# Build JSON structure
result["version"] = version.replace("gameimage-", "").replace(".x", "")
# Create containers entry
result["containers"] = {
"arch": "arch.flatimage"
}
# Add each platform with nested structure
for platform in ["linux", "pcsx2", "rpcs3", "wine", "retroarch"]:
if platform in platforms:
# Convert nested defaultdicts to regular dicts
layer_data = {}
for owner, repos in platforms[platform].items():
layer_data[owner] = {}
for repo, distributions in repos.items():
layer_data[owner][repo] = {}
for distribution, channels in distributions.items():
layer_data[owner][repo][distribution] = dict(channels)
result[platform] = {
"layer": layer_data
}
# Fetch retroarch cores from buildbot
if "retroarch" in result:
cores = fetch_retroarch_cores()
if cores:
result["retroarch"]["core"] = cores
# Print JSON with proper formatting
print(json.dumps(result, indent=2))
if __name__ == "__main__":
main()