Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / third_party / modulegraph / modulegraph / __main__.py
blob2a84cdadf69c5f2a0cdebaba1f84f8d1b37a35fe
1 from __future__ import print_function
2 import sys
3 import os
4 import optparse
5 import textwrap
6 from .modulegraph import ModuleGraph
8 def main():
9 # Parse command line
10 usage = textwrap.dedent('''\
11 Usage:
12 modulegraph [options] scriptfile ...
14 Valid options:
15 * -d: Increase debug level
16 * -q: Clear debug level
18 * -m: arguments are module names, not script files
19 * -x name: Add 'name' to the excludes list
20 * -p name: Add 'name' to the module search path
22 * -g: Output a .dot graph
23 * -h: Output a html file
24 ''')
25 parser = optparse.OptionParser(usage=usage, add_help_option=False)
26 parser.add_option('-d', action='count', dest='debug', default=1)
27 parser.add_option('-q', action='store_const', dest='debug', const=0)
29 parser.add_option('-m', action='store_true', dest='domods', default=False)
30 parser.add_option('-x', action='append', dest='excludes', default=[])
31 parser.add_option('-p', action='append', dest='addpath', default=[])
33 parser.add_option('-g', action='store_const', dest='output', const='dot')
34 parser.add_option('-h', action='store_const', dest='output', const='html')
35 opts, args = parser.parse_args()
37 if not args:
38 print("No script specified", file=sys.stderr)
39 print(usage, file=sys.stderr)
40 sys.exit(1)
42 script = args[0]
44 # Set the path based on sys.path and the script directory
45 path = sys.path[:]
46 path[0] = os.path.dirname(script)
47 path = opts.addpath + path
48 if opts.debug > 1:
49 print("path:", file=sys.stderr)
50 for item in path:
51 print(" ", repr(item), file=sys.stderr)
53 # Create the module finder and turn its crank
54 mf = ModuleGraph(path, excludes=opts.excludes, debug=opts.debug)
55 for arg in args:
56 if opts.domods:
57 if arg[-2:] == '.*':
58 mf.import_hook(arg[:-2], None, ["*"])
59 else:
60 mf.import_hook(arg)
61 else:
62 mf.run_script(arg)
63 if opts.output == 'dot':
64 mf.graphreport()
65 elif opts.output == 'html':
66 mf.create_xref()
67 else:
68 mf.report()
69 sys.exit(0)
72 if __name__ == '__main__':
73 try:
74 main()
75 except KeyboardInterrupt:
76 print("\n[interrupt]")