1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Use Python JSON to format packages.json file (#5429)

The packages JSON file which includes the boards, tools, etc. and needs to
have consistent formatting to be reproducible.  The current boards.txt.py
uses a REGEX to string-replace a bit of it, but that bit has a different
indent than the rest of the file.

Use Python's JSON writer to format the whole file repeatably.
This commit is contained in:
Earle F. Philhower, III 2018-12-03 19:26:18 -08:00 committed by Develo
parent f68362e78f
commit 2ec3daa225
2 changed files with 5 additions and 2 deletions

View File

@ -292,4 +292,4 @@
"name": "esp8266" "name": "esp8266"
} }
] ]
} }

View File

@ -37,6 +37,7 @@ import sys
import collections import collections
import getopt import getopt
import re import re
import json
# serial upload speed order in menu # serial upload speed order in menu
# default is 115 for every board unless specified with 'serial' in board # default is 115 for every board unless specified with 'serial' in board
@ -1416,9 +1417,11 @@ def package ():
newfilestr = re.sub(r'"boards":[^\]]*\],', substitution, filestr, re.MULTILINE) newfilestr = re.sub(r'"boards":[^\]]*\],', substitution, filestr, re.MULTILINE)
# To get consistent indent/formatting read the JSON and write it out programattically
if packagegen: if packagegen:
with open(pkgfname, 'w') as package_file: with open(pkgfname, 'w') as package_file:
package_file.write(newfilestr) filejson = json.loads(filestr, object_pairs_hook=collections.OrderedDict)
package_file.write(json.dumps(filejson, indent=3, separators=(',',': ')))
print("updated: %s" % pkgfname) print("updated: %s" % pkgfname)
else: else:
sys.stdout.write(newfilestr) sys.stdout.write(newfilestr)