Root/schhist/gitsch2ps

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
15usage()
16{
17    cat <<EOF 1>&2
18usage: $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
24EOF
25    exit 1
26}
27
28
29sanitize_profile=true
30sanitize_schem=true
31keep=false
32cache=false
33debug=false
34
35while 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
55done
56
57[ ! -z "$3" -a -z "$5" ] || usage
58dir=$1
59schem=$2
60sdir=`dirname "$schem"`
61if [ -z "$4" ]; then
62    commit=HEAD
63    outdir=$3
64else
65    commit=$3
66    outdir=$4
67fi
68
69[ "$dir" != "${dir#/}" ] || dir=`pwd`/$dir
70
71[ "$commit" != HEAD -o -f "$dir/$schem" ] || usage
72[ -d "$dir/.git" ] || usage
73
74if $debug; then
75    tmp=$dir/../_gitsch2ps_$commit
76else
77    tmp=$dir/../_gitsch2ps
78fi
79sch=$tmp/$sdir
80
81rm -rf "$tmp"
82rm -rf "$outdir"
83
84git clone -q -s -n "$dir/.git" "$tmp" || exit
85( cd "$tmp" && git checkout -q "$commit"; ) || exit
86
87clib=${schem%.sch}.cache.lib
88if [ -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
95fi
96
97pro=${schem%.sch}.pro
98
99if [ ! -f "$tmp/$pro" -a ! -f "$tmp/$schem" ]; then
100    echo "neither $pro nor $schem found (checked out into $tmp)" 1>&2
101    exit 1
102fi
103
104if [ ! -f "$tmp/$schem" ]; then
105    echo "$schem not found (checked out into $tmp), skipping commit" 1>&2
106    exit 0
107fi
108
109if [ ! -f "$tmp/$pro" ]; then
110    echo "$pro not found (checked out into $tmp), skipping commit" 1>&2
111    exit 0
112fi
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
122mkdir -p "$outdir"
123if $debug; then
124    cp "$sch"/*.ps "$outdir"
125else
126    mv "$sch"/*.ps "$outdir"
127fi
128
129if $keep; then
130    echo "$tmp"
131else
132    $debug || rm -rf "$tmp"
133fi
134

Archive Download this file

Branches:
master



interactive