json_data, load_errors = import_data(json_fmatch=args.fnmatch) if load_errors: # If we start getting unexpected JSON or other things, might need to # revisit quitting on load_errors print("Error loading JSON data.") for e in load_errrors: print(e) sys.exit(1) elif not json_data: print("No data loaded.") sys.exit(1) matched = [] not_matched = [] for item in json_data: if matches_all_wheres(item, args.where): matched.append(item) else: not_matched.append(item) # matched first print("[") for i, p in enumerate(matched): eol = ",\n" if i < len(matched) - 1 else "\n" print(CDDAJSONWriter(p, 1).dumps(), end=eol) print("]") # not_matched second print("[", file=sys.stderr) for i, p in enumerate(not_matched): eol = ",\n" if i < len(not_matched) - 1 else "\n"
json_data, load_errors = import_data(json_fmatch=args.fnmatch) if load_errors: # If we start getting unexpected JSON or other things, might need to # revisit quitting on load_errors print("Error loading JSON data.") for e in load_errrors: print(e) sys.exit(1) elif not json_data: print("No data loaded.") sys.exit(1) # Wasteful iteration, but less code to maintain on a tool that will likely # change again. plucked = [ item for item in json_data if matches_all_wheres(item, args.where) ] if not plucked: print("Nothing found.") sys.exit(1) elif plucked and not args.all: print(CDDAJSONWriter(plucked[0]).dumps()) else: # ugh, didn't realize JSON writer only wanted single objects when I # wrote it. # TODO: get rid of ugh print("[") for i, p in enumerate(plucked): eol = ",\n" if i < len(plucked) - 1 else "\n" print(CDDAJSONWriter(p, 1).dumps(), end=eol)
json_data, load_errors = import_data(json_fmatch=args.fnmatch) if load_errors: # If we start getting unexpected JSON or other things, might need to # revisit quitting on load_errors print("Error loading JSON data.") for e in load_errrors: print(e) sys.exit(1) elif not json_data: print("No data loaded.") sys.exit(1) # Wasteful iteration, but less code to maintain on a tool that will likely # change again. plucked = [item for item in json_data if matches_all_wheres(item, args.where)] if not plucked: print("Nothing found.") sys.exit(1) elif plucked and not args.all: print(CDDAJSONWriter(plucked[0]).dumps()) else: # ugh, didn't realize JSON writer only wanted single objects when I # wrote it. # TODO: get rid of ugh print("[") for i, p in enumerate(plucked): eol = ",\n" if i < len(plucked)-1 else "\n" print(CDDAJSONWriter(p, 1).dumps(), end=eol) print("]")
json_data, load_errors = import_data(json_fmatch=args.fnmatch) if load_errors: # If we start getting unexpected JSON or other things, might need to # revisit quitting on load_errors print("Error loading JSON data.") for e in load_errrors: print(e) sys.exit(1) elif not json_data: print("No data loaded.") sys.exit(1) matched = [] not_matched = [] for item in json_data: if matches_all_wheres(item, args.where): matched.append(item) else: not_matched.append(item) # matched first print("[") for i, p in enumerate(matched): eol = ",\n" if i < len(matched)-1 else "\n" print(CDDAJSONWriter(p, 1).dumps(), end=eol) print("]") # not_matched second print("[", file=sys.stderr) for i, p in enumerate(not_matched): eol = ",\n" if i < len(not_matched)-1 else "\n"