-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat_presets.py
More file actions
49 lines (39 loc) · 1.71 KB
/
Copy pathformat_presets.py
File metadata and controls
49 lines (39 loc) · 1.71 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
#!/usr/bin/env python
def flatten(xss):
return [x for xs in xss for x in xs]
def main():
import os.path
import tomllib
from collections import defaultdict
script_dir = os.path.dirname(os.path.realpath(__file__))
presets_path = os.path.join(script_dir, "presets.toml")
presets_by_size = defaultdict(lambda: [])
with open(presets_path, "rb") as f:
presets = tomllib.load(f)
for preset_name, preset in presets.items():
presets_by_size[(preset["width"], preset["height"])].append((preset_name, preset["devices"]))
# PRESETS.md header
print("<!--")
print(" Automatically generated from presets.toml by format_presets.py.")
print(" Do NOT update manually.")
print("-->")
print()
print("# Device Presets")
print()
print("The following device presets and dimensions are currently")
print("available (largest to smallest):")
print()
# PRESETS.md list
for dims in reversed(sorted(presets_by_size.keys())): # largest WxH first
(width, height) = dims
presets_at_size = sorted(presets_by_size[dims]) # lexically sorted preset names
preset_names = [p[0] for p in presets_at_size]
preset_devices = flatten([p[1] for p in presets_at_size])
presets_str = ", ".join(map(lambda p: f"`{p}`", preset_names))
print(f"* {presets_str} - {width} x {height}")
for device in preset_devices:
print(f" * {device}")
# PRESETS.md footer (currently blank line)
print()
if __name__ == '__main__':
main()