IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit 2921bcea47bc9926587d60469c8bbd2e02d906a8 created 13 years 7 months ago. By Werner Almesberger, New script sanitize-profile to remove glitches from a KiCad profile. | |
---|---|
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 | |
15 | OUTDIR=_out |
16 | THUMB_OPTS="-w 3 -d 60 -c 0.5,0.5,0.5 -n 1,1,0" |
17 | BG_COLOR="f0f0ff" |
18 | FNAME_COLOR="#b0f0ff" |
19 | SEP_COLOR="#000000" |
20 | |
21 | |
22 | shrink() |
23 | { |
24 | pnmscale -width 120 "$@" || exit |
25 | } |
26 | |
27 | |
28 | pngdiff() |
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 | |
43 | usage() |
44 | { |
45 | cat <<EOF 2>&1 |
46 | usage: $0 [-c cache-dir] [-n] [-S] [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 | -c cache-dir cache directory (default: same as out-dir) |
52 | -n don't use previous cache content (rebuild the cache) |
53 | -S sanitize KiCad profile |
54 | EOF |
55 | exit 1 |
56 | } |
57 | |
58 | |
59 | no_cache=false |
60 | sanitize= |
61 | |
62 | while true; do |
63 | case "$1" in |
64 | -n) no_cache=true |
65 | shift;; |
66 | -c) [ -z "$1" ] && usage |
67 | cache="$1" |
68 | shift 2;; |
69 | -S) sanitize=-S |
70 | shift;; |
71 | -*) usage;; |
72 | *) break;; |
73 | esac |
74 | done |
75 | |
76 | if [ ! -z "$1" -a -d "$1/.git" ]; then |
77 | dir="$1" |
78 | shift |
79 | else |
80 | dir=. |
81 | while [ ! -d $dir/.git ]; do |
82 | if [ $dir -ef $dir/.. ]; then |
83 | echo "no .git/ directory found in hierarchy" 1>&2 |
84 | exit 1 |
85 | fi |
86 | dir=$dir/.. |
87 | done |
88 | echo "found top-dir: $dir" 1>&2 |
89 | fi |
90 | |
91 | if [ ! -z "$1" -a -f "$dir/$1" -a \ |
92 | -f "$dir"/`dirname "$1"`/`basename "$1" .sch`.pro ]; then |
93 | sch="$1" |
94 | shift |
95 | else |
96 | for n in "$dir"/*.sch; do |
97 | [ -f `dirname "$n"`/`basename "$n" .sch`.pro ] || continue |
98 | if [ ! -z "$sch" ]; then |
99 | echo "multiple choices for top-level .sch file" 1>&2 |
100 | exit 1 |
101 | fi |
102 | sch="$n" |
103 | done |
104 | if [ -z "$sch" -o "$sch" = "$dir/*.sch" ]; then |
105 | echo "no candidate for top-level .sch file found" 1>&2 |
106 | exit 1 |
107 | fi |
108 | echo "found root sheet: $sch" 1>&2 |
109 | fi |
110 | |
111 | if [ ! -z "$1" ] && [ ! -e "$1" ] || [ -d "$1" -a ! -d "$1"/.git ]; then |
112 | out="$1" |
113 | shift |
114 | else |
115 | out=$OUTDIR |
116 | fi |
117 | [ -z "$cache" ] && cache="$out" |
118 | |
119 | [ -z "$1" ] || usage |
120 | |
121 | PATH=`dirname "$0"`:"$PATH" |
122 | first=`gitenealogy "$dir" "$sch" | sed '$s/ .*//p;d'` |
123 | schname=`gitenealogy "$dir" "$sch" | sed '$s/^.* //p;d'` |
124 | |
125 | rm -rf "$out/diff_*" "$out/thumb_*" "$out/names" |
126 | $no_cache && rm -rf "$cache" |
127 | mkdir -p "$out/names" |
128 | mkdir -p "$cache" |
129 | |
130 | head= |
131 | for n in $first `cd "$dir" && git rev-list --reverse $first..HEAD`; do |
132 | ( cd "$dir" && git show --pretty=format:'' --name-only $n; ) | |
133 | egrep -q '\.sch$|\.pro$|\.lib$' || continue |
134 | echo Processing $n |
135 | new=`gitenealogy "$dir" "$sch" | sed "/^$n /s///p;d"` |
136 | if [ ! -z "$new" ]; then |
137 | echo Name change $schname to $new 1>&2 |
138 | schname="$new" |
139 | fi |
140 | trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\"" 0 |
141 | if [ ! -d "$cache/ppm_$n" ]; then |
142 | rm -rf "$cache/ppm_$n" |
143 | mkdir "$cache/ppm_$n" |
144 | gitsch2ppm $sanitize -k "$dir" "$schname" $n "$cache/ppm_$n" || exit |
145 | gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit |
146 | fi |
147 | for m in "$cache/ppm_$n/"*; do |
148 | [ "$m" = "$cache/ppm_$n/*" ] && break |
149 | touch "$out/names/"`basename "$m" .ppm` |
150 | done |
151 | trap 0 |
152 | head=$n |
153 | done |
154 | |
155 | if [ -z "$head" ]; then |
156 | echo "no usable head found" 2>&1 |
157 | exit 1 |
158 | fi |
159 | |
160 | ppmmake '#e0e0e0' 5 20 | pnmtopng >"$out"/unchanged.png |
161 | |
162 | index="$out/index.html" |
163 | { |
164 | cat <<EOF |
165 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
166 | <HTML> |
167 | EOF |
168 | if [ ! -z "$SCHHIST_TITLE" ]; then |
169 | echo "<TITLE>$SCHHIST_TITLE</TITLE>" |
170 | fi |
171 | echo "<BODY>" |
172 | if [ ! -z "$SCHHIST_TITLE" ]; then |
173 | echo "<H1>" |
174 | [ -z "$SCHHIST_HOME_URL" ] || echo "<A href=\"$SCHHIST_HOME_URL\">" |
175 | echo "$SCHHIST_TITLE" |
176 | [ -z "$SCHHIST_HOME_URL" ] || echo "</A>" |
177 | echo "</H1>" |
178 | fi |
179 | cat <<EOF |
180 | <TABLE bgcolor="$BG_COLOR" callpadding=1> |
181 | <TR bgcolor="$FNAME_COLOR"> |
182 | EOF |
183 | for m in `ls -1 "$out/names"`; do |
184 | echo "<TD><B>$m</B>" |
185 | done |
186 | } >"$index" |
187 | |
188 | next="$head" |
189 | for n in `cd "$dir" && git rev-list $first..HEAD~1` $first; do |
190 | [ -d "$cache/ppm_$n" ] || continue |
191 | empty=true |
192 | s="<TR><TR>" |
193 | mkdir -p "$out/diff_$next" "$out/thumb_$next" |
194 | for m in `ls -1 "$out/names"`; do |
195 | a="$cache/ppm_$n/$m.ppm" |
196 | fat_a="$cache/fat_$n/$m.ppm" |
197 | b="$cache/ppm_$next/$m.ppm" |
198 | fat_b="$cache/fat_$next/$m.ppm" |
199 | diff="$out/diff_$next/$m.png" |
200 | thumb="$out/thumb_$next/$m.png" |
201 | |
202 | if [ -f "$a" -a -f "$b" ]; then |
203 | s="$s<TD align=\"center\" valign=\"middle\">" |
204 | if ! pngdiff cat "$diff" "$a" "$b"; then |
205 | s="$s<IMG src=\"unchanged.png\"" |
206 | continue |
207 | fi |
208 | pngdiff shrink "$thumb" -f $THUMB_OPTS "$fat_a" "$fat_b" \ |
209 | "$a" "$b" || exit |
210 | elif [ -f "$a" ]; then |
211 | s="$s<TD>" |
212 | pngdiff cat "$diff" -f -c 1,0,0 "$a" "$a" || exit |
213 | pngdiff shrink "$thumb" -f -c 1,0,0 $THUMB_OPTS "$fat_a" "$fat_a" \ |
214 | || exit |
215 | elif [ -f "$b" ]; then |
216 | s="$s<TD>" |
217 | pngdiff cat "$diff" -f -c 0,1,0 "$b" "$b" || exit |
218 | pngdiff shrink "$thumb" -f -c 0,1,0 $THUMB_OPTS "$fat_b" "$fat_b" \ |
219 | || exit |
220 | else |
221 | s="$s<TD>" |
222 | continue |
223 | fi |
224 | echo "$s" >>"$index" |
225 | s= |
226 | empty=false |
227 | echo "<A href=\"diff_$next/$m.png\"><IMG src=\"thumb_$next/$m.png\"></A>" >>"$index" |
228 | done |
229 | if ! $empty; then |
230 | ( |
231 | cat <<EOF |
232 | $s<TD valign="middle"> |
233 | <TABLE bgcolor="$SEP_COLOR" cellspacing=0 width="100%"><TR><TD></TABLE> |
234 | EOF |
235 | mkdir -p "$out/diff_$next" "$out/thumb_$next" |
236 | echo "<PRE>" |
237 | ( cd "$dir" && git log --pretty=short $next~1..$next; ) | |
238 | if [ -z "$SCHHIST_COMMIT_TEMPLATE" ]; then |
239 | cat |
240 | else |
241 | url=`echo "$SCHHIST_COMMIT_TEMPLATE" | sed "s/{}/$next/g"` |
242 | sed "s|^commit |<A href=\"$url\">commit</a> |" |
243 | fi | |
244 | sed '/^<.*>commit</n;s/&/&/g;s/</\</g;s/>/\>/g' |
245 | echo "</PRE>" |
246 | ) >>"$index" |
247 | fi |
248 | next=$n |
249 | done |
250 | |
251 | cat <<EOF >>"$index" |
252 | </TABLE> |
253 | <HR> |
254 | `date -u '+%F %X'` UTC |
255 | </BODY> |
256 | </HTML> |
257 | EOF |
258 |