-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgenerate.py
43 lines (30 loc) · 901 Bytes
/
generate.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
# Common code for mapfile generation scripts.
from contextlib import contextmanager
import sys
_indent: int = 0
def header(team: str = ""):
print(f"# GENERATED BY {sys.argv[0]}, DO NOT EDIT.\n\n")
if team:
print(f"# TEAM: {team}\n")
def p(*strs: list[str]):
"""Prints strs, all on one line, with all but the first quoted."""
print(" " * _indent, end="")
print(strs[0], end="")
if len(strs) > 1:
print(" ", end="")
_print_quoted(strs[1:])
def q(*strs: list[str]):
"""Prints strs, all on one line, all quoted."""
print(" " * _indent, end="")
_print_quoted(strs)
def _print_quoted(strs: list[str]):
print(*map(repr, strs))
@contextmanager
def block(typ: str):
"""Introduces an indented block of type typ. The block is closed with END."""
p(typ)
global _indent
_indent += 1
yield
_indent -= 1
p("END")