mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-29 05:21:23 +01:00
6c485625f4
The example reads a file as JSON, adds a key, then writes the new structure to a JSON file in the build folder. The example accepts a '--pretty' argument to output human readable JSON to the file.
33 lines
621 B
Python
33 lines
621 B
Python
#! /usr/bin/env python
|
|
# encoding: utf-8
|
|
# Matt Clarkson, 2015 (ita)
|
|
|
|
VERSION='0.0.1'
|
|
APPNAME='json_test'
|
|
|
|
top = '.'
|
|
|
|
import sys
|
|
import waflib.Configure
|
|
waflib.Configure.autoconfig = True
|
|
|
|
def options(opt):
|
|
opt.add_option(
|
|
'--pretty',
|
|
action = 'store_true',
|
|
help = 'pretty prints the writing of the JSON')
|
|
|
|
def configure(conf):
|
|
pass
|
|
|
|
def build(bld):
|
|
node = bld.srcnode.make_node('test.json')
|
|
json = node.read_json()
|
|
print('Read', json)
|
|
json['new_key'] = {
|
|
'number': 199
|
|
}
|
|
output = bld.bldnode.make_node('output.json')
|
|
output.write_json(json, pretty=bld.options.pretty)
|
|
print('Wrote', output.read())
|