r15599 - gnucash/trunk/src/bin - Initial proposal for a script that strips data elements from a gnucash
Christian Stimming
cstim at cvs.gnucash.org
Sun Feb 18 07:05:23 EST 2007
Author: cstim
Date: 2007-02-18 07:05:21 -0500 (Sun, 18 Feb 2007)
New Revision: 15599
Trac: http://svn.gnucash.org/trac/changeset/15599
Added:
gnucash/trunk/src/bin/gnucash-strip-svn-datafile.sh
Log:
Initial proposal for a script that strips data elements from a gnucash
data file which are not backwards-compatible to older versions of
gnucash. Discussion here:
http://lists.gnucash.org/pipermail/gnucash-devel/2007-February/019963.html
Added: gnucash/trunk/src/bin/gnucash-strip-svn-datafile.sh
===================================================================
--- gnucash/trunk/src/bin/gnucash-strip-svn-datafile.sh 2007-02-18 06:34:24 UTC (rev 15598)
+++ gnucash/trunk/src/bin/gnucash-strip-svn-datafile.sh 2007-02-18 12:05:21 UTC (rev 15599)
@@ -0,0 +1,48 @@
+#!/bin/sh
+
+# This script strips data elements from a gnucash data file that have
+# been introduced in the SVN-trunk version of gnucash, but are not
+# backwards-compatible to older versions of gnucash.
+
+ORIGFILE=$1
+ORIGTMPFILE="${ORIGFILE}.gunzip"
+BKUPFILE="${ORIGFILE}.svn.gz"
+TMPFILE="${ORIGFILE}.tmp"
+
+if [ -f ${ORIGFILE} ] ; then
+
+ # Detect compression
+ in_gzip_format=yes
+ gzip -ql ${ORIGFILE} > /dev/null 2> /dev/null || in_gzip_format=no
+
+ # Uncompress the file
+ if [ "$in_gzip_format" = "yes" ] ; then
+ gunzip -cd ${ORIGFILE} > ${ORIGTMPFILE}
+ else
+ cat ${ORIGFILE} > ${ORIGTMPFILE}
+ fi
+
+ # Remove the elements that are not backwards-compatible
+ grep -v '<sx:enabled>.</sx:enabled>' ${ORIGTMPFILE} > ${TMPFILE}
+
+ # Print result of element removal
+ echo "Removed the following elements:"
+ diff -u ${ORIGTMPFILE} ${TMPFILE}
+ echo "Keeping old data file as \"${BKUPFILE}\""
+
+ # Compress the result again
+ if [ "$in_gzip_format" = "yes" ] ; then
+ gzip -c ${ORIGTMPFILE} > ${BKUPFILE}
+ gzip -c ${TMPFILE} > ${ORIGFILE}
+ else
+ cat ${ORIGTMPFILE} > ${BKUPFILE}
+ cat ${TMPFILE} > ${ORIGFILE}
+ fi
+
+ # Remove temporary files
+ rm ${ORIGTMPFILE}
+ rm ${TMPFILE}
+
+else
+ echo "$0: File $1 not found."
+fi
Property changes on: gnucash/trunk/src/bin/gnucash-strip-svn-datafile.sh
___________________________________________________________________
Name: svn:executable
+ *
More information about the gnucash-changes
mailing list