-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschemeTableGen.py
More file actions
89 lines (75 loc) · 3.17 KB
/
schemeTableGen.py
File metadata and controls
89 lines (75 loc) · 3.17 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Generate a table to put in a scheme project readme
"""
import os
import sys
import argparse
import yaml
import pystache
# You may want to edit this to better suit your needs
template = '''
# base24-{{scheme-name-0}}-scheme
Base24 scheme for {{scheme-name}}
|baseNN|Colour|
|---|---|
|base00|
|base01|
|base02|
|base03|
|base04|
|base05|
|base06|
|base07|
|base08|
|base09|
|base0A|
|base0B|
|base0C|
|base0D|
|base0E|
|base0F|
|base10|
|base11|
|base12|
|base13|
|base14|
|base15|
|base16|
|base17|
proj-down
proj-community
'''
def get_yaml_dict(yaml_file):
"""Return a yaml_dict from reading yaml_file. If yaml_file is empty or
doesn't exist, return an empty dict instead."""
try:
with open(yaml_file, "r") as file_:
yaml_dict = yaml.safe_load(file_.read()) or {}
return yaml_dict
except FileNotFoundError:
return {}
def format_scheme(scheme):
"""Change $scheme so it can be applied to a template."""
scheme["scheme-name"] = scheme.pop("scheme")
scheme["scheme-author"] = scheme.pop("author")
scheme["scheme-name-0"] = scheme["scheme-name"].replace(" ", "-").replace("_", "-").lower()
bases = ["base{:02X}".format(x) for x in range(0, 24)]
for base in bases:
scheme["{}-hex".format(base)] = scheme.pop(base)
def main():
''' Main entry point for cli '''
parser = argparse.ArgumentParser(
description="Generate a table to put in a scheme project readme")
parser.add_argument("scheme", action="store",
help="base24 scheme file")
args = parser.parse_args()
# Check for and report level8 errors
if not os.path.isfile(args.scheme):
print(args.scheme + " is not a valid file")
sys.exit(1)
# Do the mustche template mangling and output to stdout
scheme = get_yaml_dict(args.scheme)
format_scheme(scheme)
file_content = pystache.render(template, scheme)
print(file_content)
if __name__ == "__main__":
main()