-
Notifications
You must be signed in to change notification settings - Fork 111
/
hjson_to_json.py
28 lines (23 loc) · 1.08 KB
/
hjson_to_json.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
"""Script to convert HJSON file to JSON file format."""
import hjson
import const #const.py
const.DEFAULT_CONFIG_FILE = "osx-config.hjson"
#http://stackoverflow.com/questions/244777/can-i-use-comments-inside-a-json-file#244858
const.JSON_WARNING = {'_comment': ('DO NOT EDIT THIS FILE. THIS WAS '
'AUTOMATICALLY GENERATED BY THE '
'hjson_to_json.py SCRIPT. INSTEAD, EDIT THE '
'osx-config.hjson FILE.')}
def convert(hjson_filename):
"""Convert HJson file on disk to JSON format and write to disk."""
assert hjson_filename.endswith('.hjson')
json_filename = hjson_filename.replace('.hjson', '.json')
with open(json_filename, 'w') as json_out:
with open(hjson_filename, 'r') as hjson_in:
config = hjson.loads(hjson_in.read())
config = [const.JSON_WARNING] + config
json_format = hjson.dumpsJSON(config)
json_out.write(json_format)
def _main():
convert(const.DEFAULT_CONFIG_FILE)
if __name__ == '__main__':
_main()