1 from __future__
import print_function
6 from .modulegraph
import ModuleGraph
10 usage
= textwrap
.dedent('''\
12 modulegraph [options] scriptfile ...
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
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()
38 print("No script specified", file=sys
.stderr
)
39 print(usage
, file=sys
.stderr
)
44 # Set the path based on sys.path and the script directory
46 path
[0] = os
.path
.dirname(script
)
47 path
= opts
.addpath
+ path
49 print("path:", file=sys
.stderr
)
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
)
58 mf
.import_hook(arg
[:-2], None, ["*"])
63 if opts
.output
== 'dot':
65 elif opts
.output
== 'html':
72 if __name__
== '__main__':
75 except KeyboardInterrupt:
76 print("\n[interrupt]")