From 2921bcea47bc9926587d60469c8bbd2e02d906a8 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 27 Aug 2010 20:42:40 -0300 Subject: [PATCH] New script sanitize-profile to remove glitches from a KiCad profile. - scripts/sanitize-profile: remove upsetting items from a KiCad profile - scripts/gitsch2ppm: option -S to enable sanitizing of profiles - scripts/schhist2web: pass option -S to gitsch2ppm - scripts/Makefile (xue-schhist): invoke schhist2web with option -S --- scripts/Makefile | 2 +- scripts/gitsch2ppm | 13 ++++++- scripts/sanitize-profile | 82 ++++++++++++++++++++++++++++++++++++++++ scripts/schhist2web | 11 ++++-- 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100755 scripts/sanitize-profile diff --git a/scripts/Makefile b/scripts/Makefile index a9cc249..f733f00 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -24,7 +24,7 @@ xue-schhist: SCHHIST_TITLE=Xue \ SCHHIST_HOME_URL=http://projects.qi-hardware.com/index.php/p/xue/ \ SCHHIST_COMMIT_TEMPLATE='http://projects.qi-hardware.com/index.php/p/xue/source/commit/{}/' \ - ./schhist2web ../../xue kicad/xue-rnc/xue-rnc.sch _xue + ./schhist2web -S ../../xue kicad/xue-rnc/xue-rnc.sch _xue xue-schhist-upload: rsync -a --progress _xue/{index.html,unchanged.png,thum*,diff*} \ diff --git a/scripts/gitsch2ppm b/scripts/gitsch2ppm index 08cbdd1..8a99453 100755 --- a/scripts/gitsch2ppm +++ b/scripts/gitsch2ppm @@ -43,6 +43,7 @@ usage: $0 [options] top-dir top-schem [commit] outdir -c use cached Postscript files (from previous run, with -k) -k keep checked-out tree (for immediate reuse with -c) -r XxY image resolution (default: $RES) + -S sanitize the KiCad profile -w points Postscript line width (default: $LINEWIDTH) EOF exit 1 @@ -51,6 +52,7 @@ EOF cache=false keep=false +sanitize=true while true; do case "$1" in -c) cache=true @@ -60,6 +62,9 @@ while true; do -r) [ -z "$2" ] && usage RES="$2" shift 2;; + -S) sanitize=`PATH="$PATH":\`dirname "$0"\` which sanitize-profile` + [ "$sanitize" = "${sanitize#/}" ] && sanitize=`pwd`/"$sanitize" + shift;; -w) [ -z "$2" ] && usage LINEWIDTH="$2" shift 2;; @@ -102,7 +107,13 @@ if ! $cache; then exit 1 fi - ( cd "$sch" && rm -f *.ps *.ppm && eeschema --plot "$tmp/$schem"; ) || exit + ( + cd "$sch" || exit + rm -f *.ps *.ppm + $sanitize "$tmp"/`dirname "$schem"`/`basename "$schem" .sch`.pro || + exit + eeschema --plot "$tmp/$schem" + ) || exit fi for n in "$sch"/*.ps; do diff --git a/scripts/sanitize-profile b/scripts/sanitize-profile new file mode 100755 index 0000000..3538584 --- /dev/null +++ b/scripts/sanitize-profile @@ -0,0 +1,82 @@ +#!/usr/bin/perl +# +# sanitize-profile - Remove items from a KiCad profile that may cause an upset +# +# 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. +# + + +@LIBS = ("/usr/share/kicad/library", "/usr/local/share/kicad/library"); + + +sub rewrite +{ + local ($s) = @_; + + return $s if $section ne "eeschema/libraries"; + return $s unless /^LibName(\d+)=(.*)\s*$/; + my $lib = $2; + if ($1 == $in_lib) { + $in_lib++; + } else { + print STDERR "LibName$1 when expecting $next_lib. Renumbering."; + $in_lib = $1+1; + } + $out_lib++; + my $var = "LibName$out_lib"; + if ($lib =~ /\//) { + return "$var=$lib\n" if -r "$lib.lib"; + } + for (".", $libdir, @LIBS) { + return "$var=$lib\n" if -r "$_/$lib.lib"; + } + print STDERR "cannot find $lib\n"; + $out_lib--; + return undef; +} + + +sub usage +{ + print STDERR "usage: $0 file.pro [outfile]\n"; + exit(1); +} + + +($file, $out) = @ARGV; +&usage if $#ARGV > 1; + +($dir = $file) =~ s|.*/||; +$dir = "." if $dir eq ""; + +open(FILE, $file) || die "$file: $!"; +while () { + if (/^\[(\S+)\]/) { + $section = $1; + if ($section eq "eeschema/libraries") { + $in_lib = 1; + $out_lib = 0; + } + } + if ($section eq "eeschema") { + $libdir = $2 if /^LibDir=(.*)\s*$/; + } + $s = &rewrite($_); + push(@f, $s) if defined $s; +} +close FILE; + +if (!defined $out) { + rename($file, "$file.bak"); + $out= $file; +} + +open(FILE, ">$out") || die "$out: $!"; +print FILE join("", @f) || die "$out: $!"; +close FILE || die "$out: $!"; diff --git a/scripts/schhist2web b/scripts/schhist2web index 48d3474..5f71df6 100755 --- a/scripts/schhist2web +++ b/scripts/schhist2web @@ -43,19 +43,22 @@ pngdiff() usage() { cat <&1 -usage: $0 [-c cache-dir] [-n] [top-dir] [top-schem] [out-dir] +usage: $0 [-c cache-dir] [-n] [-S] [top-dir] [top-schem] [out-dir] top-dir top-level directory of the git archive (default: locate it) top-schem root sheet of the schematics (default: locate it in top-dir) out-dir output directory (default: $OUTDIR) - -n don't use previous cache content (rebuild the cache) -c cache-dir cache directory (default: same as out-dir) + -n don't use previous cache content (rebuild the cache) + -S sanitize KiCad profile EOF exit 1 } no_cache=false +sanitize= + while true; do case "$1" in -n) no_cache=true @@ -63,6 +66,8 @@ while true; do -c) [ -z "$1" ] && usage cache="$1" shift 2;; + -S) sanitize=-S + shift;; -*) usage;; *) break;; esac @@ -136,7 +141,7 @@ for n in $first `cd "$dir" && git rev-list --reverse $first..HEAD`; do if [ ! -d "$cache/ppm_$n" ]; then rm -rf "$cache/ppm_$n" mkdir "$cache/ppm_$n" - gitsch2ppm -k "$dir" "$schname" $n "$cache/ppm_$n" || exit + gitsch2ppm $sanitize -k "$dir" "$schname" $n "$cache/ppm_$n" || exit gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit fi for m in "$cache/ppm_$n/"*; do