aboutsummaryrefslogtreecommitdiffstats
path: root/json_diff.py
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-11-30 16:59:01 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-11-30 22:15:04 +0100
commitfa8858e6b70dfabf026ef3018d702260c2405137 (patch)
treedfbc6add4ad4bc4a8cb3f86391e9bdc0793c9379 /json_diff.py
parent5bb8295a9193266a9f2a960e1825643c48c4bd1c (diff)
downloadjson_diff-fa8858e6b70dfabf026ef3018d702260c2405137.tar.gz
Set exit status of json_diff command.1.2.0
0 means no difference 1 there is a difference.
Diffstat (limited to 'json_diff.py')
-rwxr-xr-xjson_diff.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/json_diff.py b/json_diff.py
index 5d469fd..cc8bfa7 100755
--- a/json_diff.py
+++ b/json_diff.py
@@ -32,7 +32,7 @@ import logging
from optparse import OptionParser
__author__ = "Matěj Cepl"
-__version__ = "1.1.0"
+__version__ = "1.2.0"
import locale
@@ -328,6 +328,7 @@ class Comparator(object):
return self._filter_results(result)
+
def main(sys_args):
"""Main function, to process command line arguments etc."""
usage = "usage: %prog [options] old.json new.json"
@@ -345,21 +346,25 @@ def main(sys_args):
action="store_true", dest="HTMLoutput", metavar="BOOL", default=False,
help="program should output to HTML report")
(options, args) = parser.parse_args(sys_args[1:])
- print >> sys.stderr, "options = %s" % options
- print >> sys.stderr, "args = %s" % args
if len(args) != 2:
parser.error("Script requires two positional arguments, " + \
"names for old and new JSON file.")
diff = Comparator(open(args[0]), open(args[1]), options)
+ diff_res = diff.compare_dicts()
if options.HTMLoutput:
- diff_res = diff.compare_dicts()
# we want to hardcode UTF-8 here, because that's what's
# in <meta> element of the generated HTML
print(unicode(HTMLFormatter(diff_res)).encode("utf-8"))
else:
- outs = json.dumps(diff.compare_dicts(), indent=4, ensure_ascii=False)
+ outs = json.dumps(diff_res, indent=4, ensure_ascii=False)
print(outs.encode(locale.getpreferredencoding()))
+ if len(diff_res) > 0:
+ return 1
+
+ return 0
+
if __name__ == "__main__":
- main(sys.argv)
+ main_res = main(sys.argv)
+ sys.exit(main_res)