comparison env/bin/prov-compare @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 #!/Users/cmdms/OneDrive-UOB/Development/Projects/2021/sam-consensus-v3/env/bin/python3
2 # encoding: utf-8
3 """
4 prov-compare -- Compare two PROV-JSON, PROV-XML, or RDF (PROV-O) files for equivalence
5
6 @author: Trung Dong Huynh
7
8 @copyright: 2016 University of Southampton, United Kingdom. All rights reserved.
9
10 @license: MIT Licence
11
12 @contact: trungdong@donggiang.com
13 @deffield updated: 2016-10-19
14 """
15
16 from argparse import ArgumentParser, RawDescriptionHelpFormatter, FileType
17 import os
18 import sys
19 import logging
20 import traceback
21 import six
22
23 from prov.model import ProvDocument
24
25
26 logger = logging.getLogger(__name__)
27
28 __all__ = []
29 __version__ = 0.1
30 __date__ = '2015-06-16'
31 __updated__ = '2016-10-19'
32
33 DEBUG = 0
34 TESTRUN = 0
35 PROFILE = 0
36
37
38 @six.python_2_unicode_compatible
39 class CLIError(Exception):
40 """Generic exception to raise and log different fatal errors."""
41 def __init__(self, msg):
42 super(CLIError).__init__(type(self))
43 self.msg = "E: %s" % msg
44
45 def __str__(self):
46 return self.msg
47
48
49 def main(argv=None): # IGNORE:C0111
50 """Command line options."""
51
52 if argv is None:
53 argv = sys.argv
54 else:
55 sys.argv.extend(argv)
56
57 program_name = os.path.basename(sys.argv[0])
58 program_version = "v%s" % __version__
59 program_build_date = str(__updated__)
60 program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
61 program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
62 program_license = '''%s
63
64 Created by Trung Dong Huynh on %s.
65 Copyright 2016 University of Southampton. All rights reserved.
66
67 Licensed under the MIT License
68 https://github.com/trungdong/prov/blob/master/LICENSE
69
70 Distributed on an "AS IS" basis without warranties
71 or conditions of any kind, either express or implied.
72
73 USAGE
74 ''' % (program_shortdesc, str(__date__))
75
76 try:
77 # Setup argument parser
78 parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
79 parser.add_argument('file1', nargs='?', type=FileType('r'))
80 parser.add_argument('file2', nargs='?', type=FileType('r'))
81 parser.add_argument('-f', '--format1', dest='format1', action='store', default='json',
82 help='File 1\'s format: json or xml')
83 parser.add_argument('-F', '--format2', dest='format2', action='store', default='json',
84 help='File 2\'s format: json or xml')
85 parser.add_argument('-V', '--version', action='version', version=program_version_message)
86
87 args = None
88 try:
89 # Process arguments
90 args = parser.parse_args()
91 doc1 = ProvDocument.deserialize(args.file1, format=args.format1.lower())
92 doc2 = ProvDocument.deserialize(args.file2, format=args.format2.lower())
93 return doc1 != doc2
94
95 finally:
96 if args:
97 if args.file1:
98 args.file1.close()
99 if args.file2:
100 args.file2.close()
101
102 except Exception as e:
103 if DEBUG or TESTRUN:
104 traceback.print_exc()
105 raise e
106 indent = len(program_name) * " "
107 sys.stderr.write(program_name + ": " + str(e) + "\n")
108 sys.stderr.write(indent + " for help use --help")
109 return 2
110
111 if __name__ == "__main__":
112 logging.basicConfig(level=(logging.DEBUG if DEBUG else logging.INFO))
113 if TESTRUN:
114 import doctest
115 doctest.testmod()
116 if PROFILE:
117 import cProfile
118 import pstats
119 profile_filename = 'prov_compare_profile.txt'
120 cProfile.run('main()', profile_filename)
121 statsfile = open("profile_stats.txt", "wb")
122 p = pstats.Stats(profile_filename, stream=statsfile)
123 stats = p.strip_dirs().sort_stats('cumulative')
124 stats.print_stats()
125 statsfile.close()
126 sys.exit(0)
127 sys.exit(main())