Root/scripts/schhist2web

Source at commit a241265aaf21f6e1989618272105c2b7c9321ce7 created 10 years 2 months ago.
By Werner Almesberger, Run eeschema only once (not twice) per commit. 20% speed improvement.
1#!/bin/sh
2#
3# schhist2web - Web-browseable graphical revision history of schematics
4#
5# Written 2010 by Werner Almesberger
6# Copyright 2010 Werner Almesberger
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13
14
15OUTDIR=_out
16THUMB_OPTS="-w 3 -d 60 -c 0.5,0.5,0.5 -n 1,1,0"
17BG_COLOR="f0f0ff"
18FNAME_COLOR="#b0f0ff"
19SEP_COLOR="#000000"
20
21
22shrink()
23{
24    pnmscale -width 120 "$@" || exit
25}
26
27
28pngdiff()
29{
30    # pngdiff preproc outfile arg ...
31    pp="$1"
32    of="$2"
33    shift 2
34    if ! PATH=$PATH:`dirname $0`/ppmdiff ppmdiff "$@" "$out/_tmp"; then
35    rm -f "$out/_tmp"
36    return 1
37    fi
38    $pp "$out/_tmp" | pnmtopng >"$of"
39    rm "$out/_tmp"
40}
41
42
43usage()
44{
45    cat <<EOF 2>&1
46usage: $0 [-c cache-dir] [-n] [top-dir] [top-schem] [out-dir]
47
48  top-dir top-level directory of the git archive (default: locate it)
49  top-schem root sheet of the schematics (default: locate it in top-dir)
50  out-dir output directory (default: $OUTDIR)
51  -n don't use previous cache content (rebuild the cache)
52  -c cache-dir cache directory (default: same as out-dir)
53EOF
54    exit 1
55}
56
57
58no_cache=false
59while true; do
60    case "$1" in
61    -n) no_cache=true
62    shift;;
63    -c) [ -z "$1" ] && usage
64    cache="$1"
65    shift 2;;
66    -*) usage;;
67    *) break;;
68    esac
69done
70
71if [ ! -z "$1" -a -d "$1/.git" ]; then
72    dir="$1"
73    shift
74else
75    dir=.
76    while [ ! -d $dir/.git ]; do
77    if [ $dir -ef $dir/.. ]; then
78        echo "no .git/ directory found in hierarchy" 1>&2
79        exit 1
80    fi
81    dir=$dir/..
82    done
83    echo "found top-dir: $dir" 1>&2
84fi
85
86if [ ! -z "$1" -a -f "$dir/$1" -a \
87  -f "$dir"/`dirname "$1"`/`basename "$1" .sch`.pro ]; then
88    sch="$1"
89    shift
90else
91    for n in "$dir"/*.sch; do
92    [ -f `dirname "$n"`/`basename "$n" .sch`.pro ] || continue
93    if [ ! -z "$sch" ]; then
94        echo "multiple choices for top-level .sch file" 1>&2
95        exit 1
96    fi
97    sch="$n"
98    done
99    if [ -z "$sch" -o "$sch" = "$dir/*.sch" ]; then
100    echo "no candidate for top-level .sch file found" 1>&2
101    exit 1
102    fi
103    echo "found root sheet: $sch" 1>&2
104fi
105
106if [ ! -z "$1" ] && [ ! -e "$1" ] || [ -d "$1" -a ! -d "$1"/.git ]; then
107    out="$1"
108    shift
109else
110    out=$OUTDIR
111fi
112[ -z "$cache" ] && cache="$out"
113
114[ -z "$1" ] || usage
115
116PATH=`dirname "$0"`:"$PATH"
117first=`gitenealogy "$dir/$sch" | sed '$s/ .*//p;d'`
118schname=`gitenealogy "$dir/$sch" | sed '$s/^.* //p;d'`
119
120rm -rf "$out/diff_*" "$out/thumb_*" "$out/names"
121$no_cache && rm -rf "$cache"
122mkdir -p "$out/names"
123mkdir -p "$cache"
124
125head=
126for n in $first `git rev-list --reverse $first..HEAD`; do
127    git show --pretty=format:'' --name-only $n |
128      egrep -q '\.sch$|\.pro$|\.lib$' || continue
129    echo Processing $n
130    new=`gitenealogy "$dir/$sch" | sed "/^$n /s///p;d"`
131    if [ ! -z "$new" ]; then
132    echo Name change $schname to $new 1>&2
133    schname="$new"
134    fi
135    trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\"" 0
136    if [ ! -d "$cache/ppm_$n" ]; then
137    rm -rf "$cache/ppm_$n"
138    mkdir "$cache/ppm_$n"
139    gitsch2ppm -k "$dir" "$schname" $n "$cache/ppm_$n" || exit
140    gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit
141    fi
142    for m in "$cache/ppm_$n/"*; do
143    [ "$m" = "$cache/ppm_$n/*" ] && break
144    touch "$out/names/"`basename "$m" .ppm`
145    done
146    trap 0
147    head=$n
148done
149
150if [ -z "$head" ]; then
151    echo "no usable head found" 2>&1
152    exit 1
153fi
154
155index="$out/index.html"
156cat <<EOF >"$index"
157<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
158<HTML>
159<BODY>
160<TABLE bgcolor="$BG_COLOR" callpadding=1>
161<TR bgcolor="$FNAME_COLOR">
162EOF
163for m in `ls -1 "$out/names"`; do
164    echo "<TD><B>$m</B>" >>"$index"
165done
166
167next="$head"
168for n in `git rev-list $first..HEAD~1` $first; do
169    [ -d "$cache/ppm_$n" ] || continue
170    empty=true
171    s="<TR><TR>"
172    mkdir -p "$out/diff_$next" "$out/thumb_$next"
173    for m in `ls -1 "$out/names"`; do
174    a="$cache/ppm_$n/$m.ppm"
175    fat_a="$cache/fat_$n/$m.ppm"
176    b="$cache/ppm_$next/$m.ppm"
177    fat_b="$cache/fat_$next/$m.ppm"
178    diff="$out/diff_$next/$m.png"
179    thumb="$out/thumb_$next/$m.png"
180
181    if [ -f "$a" -a -f "$b" ]; then
182        s="$s<TD>"
183        pngdiff cat "$diff" "$a" "$b" || continue
184        pngdiff shrink "$thumb" -f $THUMB_OPTS "$fat_a" "$fat_b" \
185          "$a" "$b" || exit
186    elif [ -f "$a" ]; then
187        s="$s<TD>"
188        pngdiff cat "$diff" -f -c 1,0,0 "$a" "$a" || exit
189        pngdiff shrink "$thumb" -f -c 1,0,0 $THUMB_OPTS "$fat_a" "$fat_a" \
190          || exit
191    elif [ -f "$b" ]; then
192        s="$s<TD>"
193        pngdiff cat "$diff" -f -c 0,1,0 "$b" "$b" || exit
194        pngdiff shrink "$thumb" -f -c 0,1,0 $THUMB_OPTS "$fat_b" "$fat_b" \
195          || exit
196    else
197        s="$s<TD>"
198        continue
199    fi
200    echo "$s" >>"$index"
201    s=
202    empty=false
203    echo "<A href=\"diff_$next/$m.png\"><IMG src=\"thumb_$next/$m.png\"></A>" >>"$index"
204    done
205    if ! $empty; then
206    (
207        cat <<EOF
208$s<TD valign="middle">
209<TABLE bgcolor="$SEP_COLOR" cellspacing=0 width="100%"><TR><TD></TABLE>
210EOF
211    mkdir -p "$out/diff_$next" "$out/thumb_$next"
212        echo "<PRE>"
213        git log --pretty=short $next~1..$next |
214          sed 's/&/&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
215        echo "</PRE>"
216    ) >>"$index"
217    fi
218    next=$n
219done
220
221cat <<EOF >>"$index"
222</TABLE>
223<HR>
224`date -u '+%F %X'` UTC
225</BODY>
226</HTML>
227EOF
228exit 1
229

Archive Download this file



interactive