Skip to content

Instantly share code, notes, and snippets.

@crepererum
Created May 20, 2015 08:28
Show Gist options
  • Save crepererum/a054355a7c49ebbba85d to your computer and use it in GitHub Desktop.
Save crepererum/a054355a7c49ebbba85d to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# >>> About
#
# Generate a png of internal dependencies on invenio
#
# >>> Copyright
#
# Leonardo Rossi <leonardo.r@cern.h>
#
# Copyright (C) 2015 CERN.
#
# 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 2 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 <http://www.gnu.org/licenses/>.
#
# >>> Usage
#
# $> cd /src/invenio
# $> /path/to/invenio-dependencies.sh deps.png
#
# note: you need to install GraphViz
# print a list of dependencies
list_dep(){
MODULE=$1
sfood-imports $MODULE | awk -F": " '{print $2}' | grep ^invenio | sort -u
}
# print digraph for GraphViz
print_all_digraph(){
echo "digraph {"
# for each invenio module
for i in `ls invenio/modules/*/ -d -1`; do
# convert directory to python module
mod_src=`echo ${i::-1}|sed 's/\//\./g'`
# get list of dependencies on module level
MDEP=`list_dep $i | grep modules | awk -F"." '{print $1"."$2"."$3}' | sort -u`
# for each dependency
for mod_dest in `echo $MDEP`; do
if [ "$mod_src" != "$mod_dest" ]; then
echo -n "." 1>&2
echo -e "\t\"$mod_src\" -> \"$mod_dest\";"
fi
done
done
echo "}"
}
# get output file name
OUTPUT_FILE=${1}
if [ -z "$OUTPUT_FILE" ]; then
# use a temporary file
OUTPUT_FILE=`mktemp`
fi
# create a temporary file for digraph
TMPFILE=`mktemp`
print_all_digraph > $TMPFILE
# generate image
dot -Tpng $TMPFILE -o $OUTPUT_FILE
#
echo "output file: $OUTPUT_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment