-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtradis
executable file
·74 lines (56 loc) · 2.27 KB
/
tradis
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
import argparse
import sys
import importlib.metadata
import quatradis.util.cli as qutils
import quatradis.pipelines.pipeline as pipelines
import quatradis.tisp.cli as tisp
import quatradis.comparison.cli as ca
# Establish the software version from the package resources
version = importlib.metadata.version("quatradis")
def call_func(parser, args):
"""
Given a command line parser and set of pre parsed command line arguments either execute the attached function, or print
a help message to the user.
"""
if hasattr(args, "func"):
if args.verbose:
print("Command line args parsed:", args)
args.func(args)
elif args.version:
print(version)
else:
parser.print_help()
def main():
call_args = sys.argv[1:]
parser = argparse.ArgumentParser(
"""This script contains a number of tools for running or supporting TraDIS experiments.""",
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--profile', dest='profile', action='store_true',
help='Turn on profiling. Prints out cumulative time in each function to stdout and to an output file (tradis.profile). The profile file can be read by tools such as snakeviz.')
# Version option only available at top level
parser.add_argument("-V", "--version", action='store_true', default=False, help="Output the software version")
subparsers = parser.add_subparsers(title="Tradis Tools")
# Add command line parsers to the master parser from other packages
tisp.add_subparser(subparsers)
ca.add_subparser(subparsers)
pipelines.add_subparser(subparsers)
qutils.add_subparser(subparsers)
# Process CLI args
args = parser.parse_args(call_args)
# Start the profiler if requested by user
if args.profile:
import cProfile, pstats
pr = cProfile.Profile()
pr.enable()
# Do the user requested work
call_func(parser, args)
# End profiling and write out profile to disk if requested by user
if args.profile:
pr.disable()
ps = pstats.Stats(pr).sort_stats('cumulative')
print("\n\n..........Profiling stats\n")
ps.print_stats()
ps.dump_stats("tradis.profile")
if __name__ == '__main__':
main()