forked from mtkennerly/ludusavi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
72 lines (54 loc) · 1.6 KB
/
tasks.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
68
69
70
71
72
import os
import re
import shutil
from pathlib import Path
from invoke import task
ROOT = Path(__file__).parent
DIST = ROOT / "dist"
LANG = ROOT / "lang"
def get_version(ctx) -> str:
return ctx.run('cargo pkgid', hide=True).stdout.split("#")[-1].strip()
@task
def version(ctx):
print(get_version(ctx))
@task
def legal(ctx):
version = get_version(ctx)
legal_path = ROOT / "dist" / f"ludusavi-v{version}-legal.txt"
try:
ctx.run(f'cargo lichking bundle --file "{legal_path}"', hide=True)
except Exception:
pass
legal_content = legal_path.read_text("utf8")
normalized = re.sub(r"C:\\Users\\[^\\]+", "~", legal_content)
legal_path.write_text(normalized, "utf8")
@task
def flatpak(ctx, generator="/opt/flatpak-cargo-generator.py"):
ctx.run(f'python "{generator}" "{ROOT}/Cargo.lock" -o "{DIST}/generated-sources.json"', hide=True)
@task
def lang(ctx, jar="/opt/crowdin-cli/crowdin-cli.jar"):
ctx.run(f'java -jar "{jar}" pull --export-only-approved')
mapping = {}
for file in LANG.glob("*.ftl"):
if "en-US.ftl" in file.name:
continue
content = file.read_text("utf8")
if content not in mapping:
mapping[content] = set()
mapping[content].add(file)
for group in mapping.values():
if len(group) > 1:
for file in group:
file.unlink()
@task
def clean(ctx):
if DIST.exists():
shutil.rmtree(DIST, ignore_errors=True)
DIST.mkdir()
@task
def prerelease(ctx, update_lang=True):
clean(ctx)
legal(ctx)
flatpak(ctx)
if update_lang:
lang(ctx)