1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-01 20:26:15 +02:00
eda-tools/schhist/gitsch2ps

95 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#
# gitsch2ps - Generate PS files for KiCad schematics in git
#
# 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.
#
usage()
{
cat <<EOF 1>&2
usage: $0 [options] top-dir top-schem [commit] outdir
-k keep the temporary directory and print its name
-S sanitize the KiCad profile and the top-level sheet
EOF
exit 1
}
sanitize_profile=true
sanitize_schem=true
keep=false
while true; do
case "$1" in
-k) keep=true
shift;;
-S) sanitize_profile=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile`
[ "$sanitize_profile" = "${sanitize_profile#/}" ] &&
sanitize_profile=`pwd`/"$sanitize_profile"
sanitize_schem=`PATH="$PATH":\`dirname "$0"\` which sanitize-schem`
[ "$sanitize_schem" = "${sanitize_schem#/}" ] &&
sanitize_schem=`pwd`/"$sanitize_schem"
shift;;
-*)
usage;;
*)
break;;
esac
done
[ ! -z "$3" -a -z "$5" ] || usage
dir="$1"
schem="$2"
sdir=`dirname "$schem"`
if [ -z "$4" ]; then
commit=HEAD
outdir="$3"
else
commit="$3"
outdir="$4"
fi
[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
[ -d "$dir/.git" ] || usage
tmp="$dir/../_gitsch2ps"
sch="$tmp/$sdir"
rm -rf "$tmp"
rm -rf "$outdir"
git clone -q -s -n "$dir/.git" "$tmp" || exit
( cd "$tmp" && git checkout -q "$commit"; ) || exit
if [ ! -f "$tmp/$schem" ]; then
echo "$schem not found (checked out into $tmp)" 1>&2
exit 1
fi
(
cd "$sch" || exit
rm -f *.ps
$sanitize_profile "$tmp/${schem%.sch}.pro" || exit
$sanitize_schem "$tmp/$schem" || exit
eeschema --plot "$tmp/$schem"
) || exit
mkdir -p "$outdir"
mv "$sch"/*.ps "$outdir"
if $keep; then
echo "$tmp"
else
rm -rf "$tmp"
fi