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
|
#!/usr/bin/env bash
OUTPUT_FILE="deps.png"
if [ ! "$1" ] ; then
echo "Usage: graph-require.sh <lib_directory> [output_filename]"
exit 1
fi
if [ "$2" ] ; then
OUTPUT_FILE=$2
fi
grep -r '^ *require ['"'"'"]' $1 > require.txt
python <<EOF
import re
import pydot
import sys
parse_require = re.compile(
'\\\\blib/([^:]+).rb: *require ["\\']([^"\\']+)[\\'"]\$',
re.MULTILINE)
matches = [(file, dep) for (file, dep)
in parse_require.findall(file('require.txt').read())
if re.match('(yadis|openid)($|/)', dep)
]
g = pydot.graph_from_edges(matches, directed=True)
g.write_png('$OUTPUT_FILE')
EOF
|