-
Notifications
You must be signed in to change notification settings - Fork 1
/
Emma.py
94 lines (81 loc) · 3.8 KB
/
Emma.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Emma - Emma Memory and Mapfile Analyser
Copyright (C) 2019 The Emma authors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>
"""
import argparse
import Emma
import Emma.emma
import Emma.emma_vis
import Emma.emma_deltas
import Emma.shared_libs.emma_helper
from Emma.shared_libs.stringConstants import * # pylint: disable=unused-wildcard-import,wildcard-import
def initParser():
"""
Prepare the parser for Emma
We need this as a separate function for the top level sub commands (argparse).
:return: Set-up parser
"""
topLevelParser = argparse.ArgumentParser(
prog="Emma Memory and Mapfile Analyser (Emma)",
description=DESCRIPTION_EMMA,
epilog=EPILOG,
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
topLevelParser.add_argument(
"--version",
help="Display the version number.",
action="version",
version="%(prog)s, Version: " + Emma.EMMA_VERSION
)
subparser = topLevelParser.add_subparsers(dest="_invoked_emma_module") # Use `dest` to introduce a variable in order to check which sub parser was invoked
subparser.add_parser(
Emma.SUBPARSER_STRINGS.ANALYSER, # Sub parser name which will be written in `invoked_emma_module`
parents=[Emma.emma.initParser()],
help="Emma Analyser",
conflict_handler="resolve", # Since there are conflicting help messages of the top level and sub parsersr
)
subparser.add_parser(
Emma.SUBPARSER_STRINGS.VISUALISER,
parents=[Emma.emma_vis.initParser()],
help="Emma Visualiser",
conflict_handler="resolve", # Since there are conflicting help messages of the top level and sub parsersr
)
subparser.add_parser(
Emma.SUBPARSER_STRINGS.DELTAS,
parents=[Emma.emma_deltas.initParser()],
help="Emma Deltas",
conflict_handler="resolve", # Since there are conflicting help messages of the top level and sub parsersr
)
return topLevelParser
def main(arguments=""):
"""
Top level Emma script calling all Emma sub-scripts
:param arguments: Pass arguments manually (may be used for testing)
:return: None
"""
parser = initParser()
parsedArguments = Emma.shared_libs.emma_helper.parseGivenArgStrOrStdIn(arguments, parser)
emmaModuleLUT = {
Emma.SUBPARSER_STRINGS.ANALYSER: Emma.emma.main,
Emma.SUBPARSER_STRINGS.VISUALISER: Emma.emma_vis.main,
Emma.SUBPARSER_STRINGS.DELTAS: Emma.emma_deltas.main
}
# Display the top level help message if no argument is given
if parsedArguments._invoked_emma_module == None: # pylint: disable=protected-access
parser.print_help()
else:
# Dispatch emma modules
emmaModuleLUT[parsedArguments._invoked_emma_module](parsedArguments) # pylint: disable=protected-access
# We do not have to check if the LUT entry exists since argparse does that already for us
if __name__ == "__main__":
main()