1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-29 21:58:36 +02:00
eda-tools/schhist/gitsch2ps
Werner Almesberger 7b1d3fd4d2 gitsch2ps now by default removes cache.lib (option -c keeps it)
- schhist/gitsch2ps: added option -c to keep cache.lib
- schhist/gitsch2ps: remove cache.lib unless -c is set
- schhist/gitsch2ps: added missing space in warning when the profile is
  missing
2010-10-04 02:01:22 -03:00

121 lines
2.5 KiB
Bash
Executable File

#!/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
-c keep .lib.cache (default: delete it)
-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
cache=false
while true; do
case "$1" in
-c) cache=true
shift;;
-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
clib=${schem%.sch}.cache.lib
if [ -e "$tmp/$clib" ]; then
if $cache; then
echo "found $clib (keeping it)" 1>&2
else
echo "removing $clib" 1>&2
rm -f "$tmp/$clib"
fi
fi
pro=${schem%.sch}.pro
if [ ! -f "$tmp/$pro" -a ! -f "$tmp/$schem" ]; then
echo "neither $pro nor $schem found (checked out into $tmp)" 1>&2
exit 1
fi
if [ ! -f "$tmp/$schem" ]; then
echo "$schem not found (checked out into $tmp), skipping commit" 1>&2
exit 0
fi
if [ ! -f "$tmp/$pro" ]; then
echo "$pro not found (checked out into $tmp), skipping commit" 1>&2
exit 0
fi
(
cd "$sch" || exit
rm -f *.ps
$sanitize_profile "$tmp/$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