File: graph-require.sh

package info (click to toggle)
ruby-openid 2.9.2debian-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,252 kB
  • sloc: ruby: 17,952; javascript: 6,183; xml: 219; sh: 78; python: 30; makefile: 2
file content (30 lines) | stat: -rwxr-xr-x 639 bytes parent folder | download | duplicates (5)
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