aboutsummaryrefslogtreecommitdiff
path: root/scripts/jsonmodify.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/jsonmodify.py')
-rwxr-xr-xscripts/jsonmodify.py24
1 files changed, 2 insertions, 22 deletions
diff --git a/scripts/jsonmodify.py b/scripts/jsonmodify.py
index 8bd8d4556..ba1109e7a 100755
--- a/scripts/jsonmodify.py
+++ b/scripts/jsonmodify.py
@@ -59,13 +59,6 @@ class Replace(str):
cur[key] = val
-class ReplaceIfEqual(str):
- def apply(self, obj, old_val, new_val):
- cur, key = follow_path(obj, self)
- if cur and cur[key] == int(old_val):
- cur[key] = new_val
-
-
class Remove(str):
def apply(self, obj):
cur, key = follow_path(obj, self)
@@ -82,14 +75,6 @@ class AppendList(str):
raise ValueError(self + " should be a array.")
cur[key].extend(args)
-# A JSONDecoder that supports line comments start with //
-class JSONWithCommentsDecoder(json.JSONDecoder):
- def __init__(self, **kw):
- super().__init__(**kw)
-
- def decode(self, s: str):
- s = '\n'.join(l for l in s.split('\n') if not l.lstrip(' ').startswith('//'))
- return super().decode(s)
def main():
parser = argparse.ArgumentParser()
@@ -106,11 +91,6 @@ def main():
help='replace value of the key specified by path. If path doesn\'t exist, no op.',
metavar=('path', 'value'),
nargs=2, dest='patch', action='append')
- parser.add_argument("-se", "--replace-if-equal", type=ReplaceIfEqual,
- help='replace value of the key specified by path to new_value if it\'s equal to old_value.' +
- 'If path doesn\'t exist or the value is not equal to old_value, no op.',
- metavar=('path', 'old_value', 'new_value'),
- nargs=3, dest='patch', action='append')
parser.add_argument("-r", "--remove", type=Remove,
help='remove the key specified by path. If path doesn\'t exist, no op.',
metavar='path',
@@ -123,9 +103,9 @@ def main():
if args.input:
with open(args.input) as f:
- obj = json.load(f, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder)
+ obj = json.load(f, object_pairs_hook=collections.OrderedDict)
else:
- obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict, cls=JSONWithCommentsDecoder)
+ obj = json.load(sys.stdin, object_pairs_hook=collections.OrderedDict)
for p in args.patch:
p[0].apply(obj, *p[1:])