TR2X/tools/generate_rcfile
Marcin Kurczewski 73da1d8568
initial commit
2023-10-01 13:24:43 +02:00

42 lines
1.1 KiB
Python

#!/usr/bin/env python3
import argparse
from pathlib import Path
REPO_DIR = Path(__file__).parent.parent
RESOURCES_DIR = REPO_DIR / "tools" / "resources"
SRC_DIR = REPO_DIR / "src"
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("--version-file", type=Path)
parser.add_argument('-o', "--output", type=Path, nargs="+")
return parser.parse_args()
def write_rc_template(input_path: Path, output_path: Path, version: str) -> None:
template = input_path.read_text()
template = template.replace("{version}", version)
template = template.replace("{icon_path}", str(RESOURCES_DIR / "icon.ico"))
output_path.write_text(template)
def main() -> None:
args = parse_args()
if args.version_file and args.version_file.exists():
version = args.version_file.read_text().strip()
else:
version = ""
for output_path in args.output:
write_rc_template(
input_path=RESOURCES_DIR / output_path.name,
output_path=output_path,
version=version,
)
if __name__ == "__main__":
main()