Root/
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # gitsch2ps - Generate PS files for KiCad schematics in git |
| 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 | usage() |
| 16 | { |
| 17 | cat <<EOF 1>&2 |
| 18 | usage: $0 [options] top-dir top-schem [commit] outdir |
| 19 | |
| 20 | -c keep .lib.cache (default: delete it) |
| 21 | -k keep the temporary directory and print its name |
| 22 | -D debug mode: make temporary work tree unique and keep it |
| 23 | -S sanitize the KiCad profile and the top-level sheet |
| 24 | EOF |
| 25 | exit 1 |
| 26 | } |
| 27 | |
| 28 | |
| 29 | sanitize_profile=true |
| 30 | sanitize_schem=true |
| 31 | keep=false |
| 32 | cache=false |
| 33 | debug=false |
| 34 | |
| 35 | while true; do |
| 36 | case "$1" in |
| 37 | -c) cache=true |
| 38 | shift;; |
| 39 | -k) keep=true |
| 40 | shift;; |
| 41 | -D) debug=true; |
| 42 | shift;; |
| 43 | -S) sanitize_profile=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile` |
| 44 | [ "$sanitize_profile" = "${sanitize_profile#/}" ] && |
| 45 | sanitize_profile=`pwd`/"$sanitize_profile" |
| 46 | sanitize_schem=`PATH="$PATH":\`dirname "$0"\` which sanitize-schem` |
| 47 | [ "$sanitize_schem" = "${sanitize_schem#/}" ] && |
| 48 | sanitize_schem=`pwd`/"$sanitize_schem" |
| 49 | shift;; |
| 50 | -*) |
| 51 | usage;; |
| 52 | *) |
| 53 | break;; |
| 54 | esac |
| 55 | done |
| 56 | |
| 57 | [ ! -z "$3" -a -z "$5" ] || usage |
| 58 | dir=$1 |
| 59 | schem=$2 |
| 60 | sdir=`dirname "$schem"` |
| 61 | if [ -z "$4" ]; then |
| 62 | commit=HEAD |
| 63 | outdir=$3 |
| 64 | else |
| 65 | commit=$3 |
| 66 | outdir=$4 |
| 67 | fi |
| 68 | |
| 69 | [ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir |
| 70 | |
| 71 | [ "$commit" != HEAD -o -f "$dir/$schem" ] || usage |
| 72 | [ -d "$dir/.git" ] || usage |
| 73 | |
| 74 | if $debug; then |
| 75 | tmp=$dir/../_gitsch2ps_$commit |
| 76 | else |
| 77 | tmp=$dir/../_gitsch2ps |
| 78 | fi |
| 79 | sch=$tmp/$sdir |
| 80 | |
| 81 | rm -rf "$tmp" |
| 82 | rm -rf "$outdir" |
| 83 | |
| 84 | git clone -q -s -n "$dir/.git" "$tmp" || exit |
| 85 | ( cd "$tmp" && git checkout -q "$commit"; ) || exit |
| 86 | |
| 87 | clib=${schem%.sch}.cache.lib |
| 88 | if [ -e "$tmp/$clib" ]; then |
| 89 | if $cache; then |
| 90 | echo "found $clib (keeping it)" 1>&2 |
| 91 | else |
| 92 | echo "removing $clib" 1>&2 |
| 93 | rm -f "$tmp/$clib" |
| 94 | fi |
| 95 | fi |
| 96 | |
| 97 | pro=${schem%.sch}.pro |
| 98 | |
| 99 | if [ ! -f "$tmp/$pro" -a ! -f "$tmp/$schem" ]; then |
| 100 | echo "neither $pro nor $schem found (checked out into $tmp)" 1>&2 |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
| 104 | if [ ! -f "$tmp/$schem" ]; then |
| 105 | echo "$schem not found (checked out into $tmp), skipping commit" 1>&2 |
| 106 | exit 0 |
| 107 | fi |
| 108 | |
| 109 | if [ ! -f "$tmp/$pro" ]; then |
| 110 | echo "$pro not found (checked out into $tmp), skipping commit" 1>&2 |
| 111 | exit 0 |
| 112 | fi |
| 113 | |
| 114 | ( |
| 115 | cd "$sch" || exit |
| 116 | rm -f *.ps |
| 117 | $sanitize_profile "$tmp/$pro" || exit |
| 118 | $sanitize_schem "$tmp/$schem" || exit |
| 119 | eeschema --plot=ps --plot-bw "$tmp/$schem" |
| 120 | ) || exit |
| 121 | |
| 122 | mkdir -p "$outdir" |
| 123 | if $debug; then |
| 124 | cp "$sch"/*.ps "$outdir" |
| 125 | else |
| 126 | mv "$sch"/*.ps "$outdir" |
| 127 | fi |
| 128 | |
| 129 | if $keep; then |
| 130 | echo "$tmp" |
| 131 | else |
| 132 | $debug || rm -rf "$tmp" |
| 133 | fi |
| 134 |
Branches:
master
