1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-12-23 20:56:45 +02:00
ben-wpan/scripts/schhist2web
Werner Almesberger d7d95ff2da Allow schhist2web and friends to run from a directory outside the working tree.
- scripts/gitenealogy: now requires the repository directory to be passed
- scripts/schhist2web: adapted for above change
- scripts/schhist2web: change to the repository's directory before each
  call to git
- scripts/Makefile: added demo upload and Xue build
- scripts/Makefile (all): added usage information
2010-08-27 19:32:52 -03:00

253 lines
5.9 KiB
Bash
Executable File

#!/bin/sh
#
# schhist2web - Web-browseable graphical revision history of schematics
#
# Written 2010 by Werner Almesberger
# Copyright 2010 Werner Almesberger
#
# 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.
#
OUTDIR=_out
THUMB_OPTS="-w 3 -d 60 -c 0.5,0.5,0.5 -n 1,1,0"
BG_COLOR="f0f0ff"
FNAME_COLOR="#b0f0ff"
SEP_COLOR="#000000"
shrink()
{
pnmscale -width 120 "$@" || exit
}
pngdiff()
{
# pngdiff preproc outfile arg ...
pp="$1"
of="$2"
shift 2
if ! PATH=$PATH:`dirname $0`/ppmdiff ppmdiff "$@" "$out/_tmp"; then
rm -f "$out/_tmp"
return 1
fi
$pp "$out/_tmp" | pnmtopng >"$of"
rm "$out/_tmp"
}
usage()
{
cat <<EOF 2>&1
usage: $0 [-c cache-dir] [-n] [top-dir] [top-schem] [out-dir]
top-dir top-level directory of the git archive (default: locate it)
top-schem root sheet of the schematics (default: locate it in top-dir)
out-dir output directory (default: $OUTDIR)
-n don't use previous cache content (rebuild the cache)
-c cache-dir cache directory (default: same as out-dir)
EOF
exit 1
}
no_cache=false
while true; do
case "$1" in
-n) no_cache=true
shift;;
-c) [ -z "$1" ] && usage
cache="$1"
shift 2;;
-*) usage;;
*) break;;
esac
done
if [ ! -z "$1" -a -d "$1/.git" ]; then
dir="$1"
shift
else
dir=.
while [ ! -d $dir/.git ]; do
if [ $dir -ef $dir/.. ]; then
echo "no .git/ directory found in hierarchy" 1>&2
exit 1
fi
dir=$dir/..
done
echo "found top-dir: $dir" 1>&2
fi
if [ ! -z "$1" -a -f "$dir/$1" -a \
-f "$dir"/`dirname "$1"`/`basename "$1" .sch`.pro ]; then
sch="$1"
shift
else
for n in "$dir"/*.sch; do
[ -f `dirname "$n"`/`basename "$n" .sch`.pro ] || continue
if [ ! -z "$sch" ]; then
echo "multiple choices for top-level .sch file" 1>&2
exit 1
fi
sch="$n"
done
if [ -z "$sch" -o "$sch" = "$dir/*.sch" ]; then
echo "no candidate for top-level .sch file found" 1>&2
exit 1
fi
echo "found root sheet: $sch" 1>&2
fi
if [ ! -z "$1" ] && [ ! -e "$1" ] || [ -d "$1" -a ! -d "$1"/.git ]; then
out="$1"
shift
else
out=$OUTDIR
fi
[ -z "$cache" ] && cache="$out"
[ -z "$1" ] || usage
PATH=`dirname "$0"`:"$PATH"
first=`gitenealogy "$dir" "$sch" | sed '$s/ .*//p;d'`
schname=`gitenealogy "$dir" "$sch" | sed '$s/^.* //p;d'`
rm -rf "$out/diff_*" "$out/thumb_*" "$out/names"
$no_cache && rm -rf "$cache"
mkdir -p "$out/names"
mkdir -p "$cache"
head=
for n in $first `cd "$dir" && git rev-list --reverse $first..HEAD`; do
( cd "$dir" && git show --pretty=format:'' --name-only $n; ) |
egrep -q '\.sch$|\.pro$|\.lib$' || continue
echo Processing $n
new=`gitenealogy "$dir" "$sch" | sed "/^$n /s///p;d"`
if [ ! -z "$new" ]; then
echo Name change $schname to $new 1>&2
schname="$new"
fi
trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\"" 0
if [ ! -d "$cache/ppm_$n" ]; then
rm -rf "$cache/ppm_$n"
mkdir "$cache/ppm_$n"
gitsch2ppm -k "$dir" "$schname" $n "$cache/ppm_$n" || exit
gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit
fi
for m in "$cache/ppm_$n/"*; do
[ "$m" = "$cache/ppm_$n/*" ] && break
touch "$out/names/"`basename "$m" .ppm`
done
trap 0
head=$n
done
if [ -z "$head" ]; then
echo "no usable head found" 2>&1
exit 1
fi
ppmmake '#e0e0e0' 5 20 | pnmtopng >"$out"/unchanged.png
index="$out/index.html"
{
cat <<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
EOF
if [ ! -z "$SCHHIST_TITLE" ]; then
echo "<TITLE>$SCHHIST_TITLE</TITLE>"
fi
echo "<BODY>"
if [ ! -z "$SCHHIST_TITLE" ]; then
echo "<H1>"
[ -z "$SCHHIST_HOME_URL" ] || echo "<A href=\"$SCHHIST_HOME_URL\">"
echo "$SCHHIST_TITLE"
[ -z "$SCHHIST_HOME_URL" ] || echo "</A>"
echo "</H1>"
fi
cat <<EOF
<TABLE bgcolor="$BG_COLOR" callpadding=1>
<TR bgcolor="$FNAME_COLOR">
EOF
for m in `ls -1 "$out/names"`; do
echo "<TD><B>$m</B>"
done
} >"$index"
next="$head"
for n in `cd "$dir" && git rev-list $first..HEAD~1` $first; do
[ -d "$cache/ppm_$n" ] || continue
empty=true
s="<TR><TR>"
mkdir -p "$out/diff_$next" "$out/thumb_$next"
for m in `ls -1 "$out/names"`; do
a="$cache/ppm_$n/$m.ppm"
fat_a="$cache/fat_$n/$m.ppm"
b="$cache/ppm_$next/$m.ppm"
fat_b="$cache/fat_$next/$m.ppm"
diff="$out/diff_$next/$m.png"
thumb="$out/thumb_$next/$m.png"
if [ -f "$a" -a -f "$b" ]; then
s="$s<TD align=\"center\" valign=\"middle\">"
if ! pngdiff cat "$diff" "$a" "$b"; then
s="$s<IMG src=\"unchanged.png\""
continue
fi
pngdiff shrink "$thumb" -f $THUMB_OPTS "$fat_a" "$fat_b" \
"$a" "$b" || exit
elif [ -f "$a" ]; then
s="$s<TD>"
pngdiff cat "$diff" -f -c 1,0,0 "$a" "$a" || exit
pngdiff shrink "$thumb" -f -c 1,0,0 $THUMB_OPTS "$fat_a" "$fat_a" \
|| exit
elif [ -f "$b" ]; then
s="$s<TD>"
pngdiff cat "$diff" -f -c 0,1,0 "$b" "$b" || exit
pngdiff shrink "$thumb" -f -c 0,1,0 $THUMB_OPTS "$fat_b" "$fat_b" \
|| exit
else
s="$s<TD>"
continue
fi
echo "$s" >>"$index"
s=
empty=false
echo "<A href=\"diff_$next/$m.png\"><IMG src=\"thumb_$next/$m.png\"></A>" >>"$index"
done
if ! $empty; then
(
cat <<EOF
$s<TD valign="middle">
<TABLE bgcolor="$SEP_COLOR" cellspacing=0 width="100%"><TR><TD></TABLE>
EOF
mkdir -p "$out/diff_$next" "$out/thumb_$next"
echo "<PRE>"
( cd "$dir" && git log --pretty=short $next~1..$next; ) |
if [ -z "$SCHHIST_COMMIT_TEMPLATE" ]; then
cat
else
url=`echo "$SCHHIST_COMMIT_TEMPLATE" | sed "s/{}/$next/g"`
sed "s|^commit |<A href=\"$url\">commit</a> |"
fi |
sed '/^<.*>commit</n;s/&/&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
echo "</PRE>"
) >>"$index"
fi
next=$n
done
cat <<EOF >>"$index"
</TABLE>
<HR>
`date -u '+%F %X'` UTC
</BODY>
</HTML>
EOF