mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2026-01-27 10:22:15 +00:00
All editing of an existing json file.
This commit is contained in:
@@ -30,6 +30,7 @@ def setkeypath(d, kvt):
|
||||
|
||||
ap=argparse.ArgumentParser(description="Simple JSON Generator.")
|
||||
|
||||
ap.add_argument("--in", metavar='FILENAME', help="Load json source data.", dest='_in')
|
||||
ap.add_argument("--kj", nargs=2, metavar=('KEY', 'FILE|STR'), help="Add json data.")
|
||||
ap.add_argument("--ky", nargs=2, metavar=('KEY', 'FILE|STR'), help="Add yaml jdata.")
|
||||
ap.add_argument("--kv", nargs=2, metavar=('KEY', 'VALUE'), help="Add key/value pair.")
|
||||
@@ -37,11 +38,18 @@ ap.add_argument("--kl", nargs='+', metavar=('KEY', 'ENTRY'), help="Add key/l
|
||||
ap.add_argument("--out", metavar='FILENAME', help="Write output to the given file. The default is stdout")
|
||||
ap.add_argument("--indent", nargs=1, help="Json output indentation value. Default is 2", default=2)
|
||||
ap.add_argument("--no-nl", action='store_true', help="No newline at the end of the output.")
|
||||
ap.add_argument("--inout", metavar='FILENAME', help="Modify. Equivalent to --in FILENAME --out FILENAME")
|
||||
ops = ap.parse_args();
|
||||
|
||||
if ops.inout:
|
||||
ops._in = ops.inout
|
||||
ops.out = ops.inout
|
||||
|
||||
g_data={}
|
||||
|
||||
if ops._in:
|
||||
g_data = json.load(open(ops._in))
|
||||
|
||||
if ops.kj:
|
||||
(k, j) = ops.kj
|
||||
if os.path.exists(j):
|
||||
|
||||
Reference in New Issue
Block a user