def main(argv=None): args = _configure_arg_parser().parse_args(argv) if args.export_path == '-': # read input from stdin try: export_json = json.load(sys.stdin) except Exception: # pylint: disable=broad-except print('error: could not parse JSON from stdin', file=sys.stderr) return 1 else: # read input from a file try: args.export_path = abspath(expanduser(args.export_path)) with open(args.export_path, 'r', encoding='utf-8') as f: export_json = json.load(f) except Exception: # pylint: disable=broad-except print("error: could not read from file: {}".format( args.export_path), file=sys.stderr) return 1 convert(export_json, security_tag=args.security_tag) export_json = reorder_ties_json(export_json) if args.output_file is not None: # write output to the specified file path try: args.output_file = abspath(expanduser(args.output_file)) with open(args.output_file, 'w', encoding='utf-8') as f: json.dump(export_json, f, indent=2) return 0 except Exception: # pylint: disable=broad-except print("error: could not write to file: {}".format( args.output_file), file=sys.stderr) return 1 elif args.in_place: if args.export_path == '-': # input came from stdin, write output to stdout json.dump(export_json, sys.stdout, indent=2) return 0 else: # input came from a file, write output back to the same file try: args.export_path = abspath(expanduser(args.export_path)) with open(args.export_path, 'w', encoding='utf-8') as f: json.dump(export_json, f, indent=2) return 0 except Exception: # pylint: disable=broad-except print("error: could not write to file: {}".format( args.export_path), file=sys.stderr) return 1 else: # no output file and not in-place, write output to stdout json.dump(export_json, sys.stdout, indent=2) return 0
def test_version_0_dot_1_dot_8(self): ties_json = {'version': '0.1.8'} convert(ties_json, 'U') self.assertEqual(ties_json['version'], '0.9')
def test_version_0_dot_9(self): ties_json = {'version': '0.9'} convert(ties_json) self.assertEqual(ties_json['version'], '0.9')
def test_version_unknown_version(self): ties_json = {'version': '0.1'} convert(ties_json, 'U') self.assertEqual(ties_json['version'], '0.1')