Repository navigation
Expand file tree
/
Copy pathreplacer.py
More file actions
57 lines (43 loc) · 1.44 KB
/
Copy pathreplacer.py
File metadata and controls
57 lines (43 loc) · 1.44 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
#!/usr/bin/env python
import sys
import os
import subprocess
# from genice2.tool import line_replacer
# import distutils.core
from logging import getLogger, INFO, basicConfig
from jinja2 import Environment, FileSystemLoader
import json
import toml
from trainscanner.i18n import tr, init_translations
basicConfig(level=INFO, format="%(levelname)s %(message)s")
logger = getLogger()
logger.debug("Debug mode.")
init_translations()
def add_prefix(L: list[str], prefix: str = " "):
return prefix + ("\n" + prefix).join(L) + "\n"
def get_usage(command: str, short_command: str):
return "".join(
os.popen(f"python -m trainscanner.converter.{command} --help").readlines()
).replace(f"python -m trainscanner.converter.{command}", short_command)
project = toml.load("pyproject.toml")
project |= {
"usage_helicify": get_usage("helix", "helicify"),
"usage_rectify": get_usage("rect", "rectify"),
"usage_movify": get_usage("movie", "movify"),
}
branch = subprocess.run(
["git", "branch", "--show-current"], capture_output=True, text=True
).stdout.strip()
if branch == "main":
branch = ""
else:
branch = f"#{branch}"
project["branch"] = branch
# テンプレートの内容を標準入力から読み込む
template_content = sys.stdin.read()
# Jinja2環境を設定
env = Environment(loader=FileSystemLoader("."))
t = env.from_string(template_content)
# レンダリング
markdown_en = t.render(**project)
print(markdown_en)