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
|
#!/usr/bin/env python3
import argparse
import dataclasses
import os
import pathlib
import shutil
import subprocess
import sys
DESCRIPTION = "Script to convert main icon file to all required formats"
SCRIPT = pathlib.Path(__file__).resolve()
ICON = SCRIPT.parent
MAIN = ICON / "main.svg"
ANDROID = ICON / "android"
LINUX = ICON / "linux"
def main() -> None:
_ = Arguments.from_list(sys.argv)
os.makedirs(ANDROID, exist_ok=True)
inkscape(MAIN, ANDROID / "default.png")
inkscape(MAIN, ANDROID / "foreground.png", ids=("foreground",))
inkscape(MAIN, ANDROID / "background.png", ids=("background",))
os.makedirs(LINUX, exist_ok=True)
shutil.copyfile(MAIN, LINUX / "scalable.svg")
inkscape(MAIN, LINUX / "16.png", size=16)
inkscape(MAIN, LINUX / "32.png", size=32)
inkscape(MAIN, LINUX / "48.png", size=48)
inkscape(MAIN, LINUX / "64.png", size=64)
inkscape(MAIN, LINUX / "128.png", size=128)
inkscape(MAIN, LINUX / "256.png", size=256)
inkscape(MAIN, LINUX / "512.png", size=512)
@dataclasses.dataclass(frozen=True, kw_only=True)
class Arguments:
@staticmethod
def from_list(args: list[str]) -> "Arguments":
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.parse_args(args[1:])
return Arguments()
def inkscape(
source: pathlib.Path,
sink: pathlib.Path,
ids: tuple[str, ...] = ("foreground", "background"),
size: int = 1024,
) -> None:
subprocess.run(
(
# fmt: off
"inkscape", str(source),
"--export-filename", str(sink),
"--export-area-page",
"--export-id", ";".join(ids),
"--export-width", str(size),
"--export-height", str(size),
"--export-id-only",
# fmt: on
),
check=True,
shell=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
if __name__ == "__main__":
main()
|