From dadc34655c3ab961b0b0b94a10eaaba710f0b5e8 Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 4 Jul 2011 22:38:03 +0000 Subject: Added kmymoney git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- contrib/Makefile.am | 1 + contrib/README | 6 ++ contrib/csvbankingqif.py | 151 ++++++++++++++++++++++++++++++++ contrib/csvpricesqif.py | 59 +++++++++++++ contrib/csvsecurityqif.py | 57 ++++++++++++ contrib/functions.mysql | 182 +++++++++++++++++++++++++++++++++++++++ contrib/kmm-safe | 49 +++++++++++ contrib/mysqlcrypt.sh | 99 +++++++++++++++++++++ contrib/splitup-kde-chunk-online | 88 +++++++++++++++++++ contrib/viewxml.sh | 45 ++++++++++ 10 files changed, 737 insertions(+) create mode 100644 contrib/Makefile.am create mode 100644 contrib/README create mode 100755 contrib/csvbankingqif.py create mode 100755 contrib/csvpricesqif.py create mode 100755 contrib/csvsecurityqif.py create mode 100644 contrib/functions.mysql create mode 100755 contrib/kmm-safe create mode 100644 contrib/mysqlcrypt.sh create mode 100755 contrib/splitup-kde-chunk-online create mode 100755 contrib/viewxml.sh (limited to 'contrib') diff --git a/contrib/Makefile.am b/contrib/Makefile.am new file mode 100644 index 0000000..e55826f --- /dev/null +++ b/contrib/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = README kmm-safe functions.mysql mysqlcrypt.sh splitup-kde-chunk-online viewxml.sh csvpricesqif.py csvsecurityqif.py csvbankingqif.py diff --git a/contrib/README b/contrib/README new file mode 100644 index 0000000..1bf2388 --- /dev/null +++ b/contrib/README @@ -0,0 +1,6 @@ +This directory contains various tools around KMyMoney. They +are not part of the installation and contained here for your +reference. + +@Developers: Make sure to add new files in this directory + to the EXTRA_DIST target in Makefile.am diff --git a/contrib/csvbankingqif.py b/contrib/csvbankingqif.py new file mode 100755 index 0000000..4e0d7ea --- /dev/null +++ b/contrib/csvbankingqif.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-1 -*- +# +#*************************************************************************** +# csvbankingqif.py - description +# ------------------- +# begin : Sat 31 Oct. 2009 +# copyright : (C) 2009 by Allan Anderson +# email : aganderson@ukonline.co.uk +# +#***************************************************************************/ +# +#*************************************************************************** +#* * +#* 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. * +#* * +#***************************************************************************/ +# +# *** NOTE *** +# It may be necessary to remove the second line, before running. +# It may be necessary also, to change the currency symbol if your file +# includes one. +# +# Simple utility to convert a csv format file, as from a bank, to qif +# format for KMyMoney2. There is no standard for the layout of such a +# file, but generally there will be a header line which indicates the +# layout of the fields within the file. Even then though, the order of +# the columns may vary. It is assumed, though, that the first column +# will contain the date, in 'dd MM yy' format, 'MM' being the month +# name or number. +# The second column is the detail. The third and fourth columns are +# assumed to be debits and credits. Even fron the same bank, these +# columns may be reversed, but the script handles this. Alternatively, +# the third column may be the amount. There may also be additional +# columns, such as current balance, but these are all ignored. +# Apart from the header line, there are likely to be other lines, with +# account number, balance details, etc. These are skipped. +# +# First, make the script executable: chmod u+x csvbankinyqif.py . +# The script should be added to the KMM QIF import profile. In KMM, open +# Tools/QIF Profile Editor and click on 'New' at the bottom. then enter a +# name, such as csvbank, then click 'OK'. Next, click on that name in the +# next window, and open the Filter tab. For the 'Input filter location', +# select the location you chose for the script file. For the Input filter +# file type, enter *.csv, or whatever extension your data file has. +# Finally, click 'OK'. +# When ready, select File/Import/QIF, and browse to your data file, then +# select your new filter profile, and click 'Import'. +# + +#desc="date","detail","debit","credit" +mnths=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] +currency = '£' +setup = True +debsfirst = False # credit column is before debit +both = False # only one amount column +print("!Type:Bank") +while 1: + try: + line=raw_input() + except:break + if line == "" : continue # empty line + line = line.replace('"','',) # Strip out ' "' quotes + line = line.replace(currency,'',) # Strip out '£', etc. symbol + cols = line.split(',') # Seperator between columns + if setup: +# +# *** SETUP *** +# + dt = cols[0][0:2] # Might be a date (day) + datefound = ((dt > '0') and (dt < '32')) #this looks like a date + hdrfound = (cols[0] == 'Date') + if not datefound and not hdrfound: continue# still in hdrs + if hdrfound: +# +# *** 'Date', so now in header *** +# + hdrfound = False + #line = line.replace(' ','',) # Strip out spaces in hdr + cols[2] = cols[2].replace(' ','',) # Strip out spaces in hdr + if cols[2] == 'Debits': + debsfirst = True + continue + elif cols[2] == 'Credits': + debsfirst = False + continue + elif cols[2] == 'Amount': + both = True + continue + else: + print 'Error in col[2]' + print '*** Error in header - col 2 s/b Debit, Credit, or Amount' + #continue + exit + setup ==False +# +# *** Transactions *** +# + cnum = 0 # First column + for col in cols: + if cnum > 3: break +# +# # Process Date +# + elif cnum == 0: + col =col.replace(' ','/',2) # Change date seperator to '/' + m = col.split('/') +# *** Check if month not numeric + mn = m[1][0:3] # Extract month string from field 2 + fld = 2 + try: + mnth = mnths.index(mn) # Get month number + except ValueError: # Field 2 not a valid month name + mn = m[0][0:3] # .. so try field 1 + fld = 1 + try: + mnth = mnths.index(mn) + except ValueError: # Nor is field 1 + dat = ''.join(col) # ..so use as is (numeric) + else: # Field 1 is month name + dat = col[1:3] + str(mnth + 1) + '/' +m[2] + else: # Field 2 is month name + dat = col[0:3] + str(mnth + 1) + '/' +m[2] + line = 'D' + dat+'\n' +# +# # Detail column +# + elif cnum == 1: + #col = col.replace('"','') + line = line + 'P' + col +'\n' +# +# # Debit or credit column +# + elif cnum == 2: + if col != "": + if debsfirst == True: # This is Debit column + col = '-' + col # Mark as -ve + line = line + 'T' + col +'\n' +# +# # Credit or debit? +# + elif ((cnum == 3) and (both == False)): + if col != "": + if ((debsfirst == False) ): + col = '-' + col # Mark as -ve + line = line + 'T' + col + '\n' + cnum+=1 + print line + '^' # output this entry diff --git a/contrib/csvpricesqif.py b/contrib/csvpricesqif.py new file mode 100755 index 0000000..656ce20 --- /dev/null +++ b/contrib/csvpricesqif.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +#*************************************************************************** +# csvpricesqif.py - description +# ------------------- +# begin : Sat 24 Oct. 2009 +# copyright : (C) 2009 by Allan Anderson +# email : aganderson@ukonline.co.uk +# +#***************************************************************************/ +# +#*************************************************************************** +#* * +#* 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. * +#* * +#***************************************************************************/ + +import csv + +# *** NOTE *** +# It may be necessary to remove the second line, before running. + +# Simple script to convert a csv format Prices file, as from later +# editions of Quicken, to qif format for KMyMoney2. +# It and its data files are expected to be in the same directory. +# First make the script executable:- chmod u+x csvpricesqif.py +# Run by ''./csvpricesqif.py' . +# You will be prompted to enter input and output filenames, followed +# by the symbol for the stock. + +# Input format - "23.12.09","61.62",,, +# Output format - +# !Type:Prices +# "HJU8.BE",61.62,"23.12.09" +# ^ + +fin = raw_input('Please enter the input Prices filename (.csv, .PRN, etc.) : ') +fout = raw_input('Please enter the output filename (add .qif) : ') +symbol = raw_input('Please enter the symbol for this stock: ') +symbol ='"'+ symbol+'"'# Add " " around symbol + +inputfile = csv.reader(open(fin, 'rb')) +outputfile = open(fout, 'w') +inputfile.next() # Skip header line. Comment out if no header. +inputfile_list = [] +inputfile_list.extend(inputfile) + +for data in inputfile_list: + line = '!Type:Prices\n' + line = line +symbol +',' + data[1] + ',"' + data[0] + '"\n' + '^\n' + + #print line + outputfile.write(line) + +outputfile.close() diff --git a/contrib/csvsecurityqif.py b/contrib/csvsecurityqif.py new file mode 100755 index 0000000..5f5e888 --- /dev/null +++ b/contrib/csvsecurityqif.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +#*************************************************************************** +# csvsecurityqif.py - description +# ------------------- +# begin : Sat 24 Oct. 2009 +# copyright : (C) 2009 by Allan Anderson +# email : aganderson@ukonline.co.uk +# +#***************************************************************************/ +# +#*************************************************************************** +#* * +#* 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. * +#* * +#***************************************************************************/ +import csv + +# *** NOTE *** +# It may be necessary to remove the second line, before running. + +# Simple utility to convert a csv format Securities file, as from later +# editions of Quicken, to qif format for KMyMoney2. +# It and its data files are expected to be in the same directory. +# +# First, make the script executable: chmod u+x csvsecurityqif.py . +# Run by './csvsecurityqif.py'. +# You will be prompted to enter input and output filenames. +# The entries in this input file contain a number of fields that are +# not documented and which KMyMoney2 does not handle. +# These fields are accepted and suffixed with 'M' in the output file. +# Anything of importance in them will need to be copy/pasted into KMM. + +fin = raw_input('Please enter the input Securities filename (.csv, .PRN, etc.) : ') +fout = raw_input('Please enter the output filename (add .qif) : ') +line = csv.reader(open(fin, "rb")) +outputfile = open(fout, 'w') +line.next() # Skip header line. Comment out if no header. +line_list = [] +line_list.extend(line) +line = "!Option:AutoSwitch\n" +outputfile.write(line) + +for data in line_list: + line = "!Account\n" + "N" +data[0] + "\n" + "TMutual\n" + "^\n" + line = line + "!Type:Security\n" + line = line + "N" +data[0] + "\n"+ "S" + data[1] + "\n"+ "TUnit/Inv. Trust" #+"\n" + line = line + "M" + data[2] + "\n"+ "M" + data[3] + "\n"+ "M" + data[4] + "\n"+ "M" + data[5] + "\n"+ "M" + data[6] + line = line + "\n^\n" + #print line + outputfile.write(line) + +outputfile.close() diff --git a/contrib/functions.mysql b/contrib/functions.mysql new file mode 100644 index 0000000..c8c6c7f --- /dev/null +++ b/contrib/functions.mysql @@ -0,0 +1,182 @@ +/* functions.mysql + Some functions for use with a KMyMoney MySql database. + Load them into your database with command: + mysql KMyMoney < this_file + To preserve them in backups, remember to add the -R flag to mysqldump. +*/ + +delimiter // + +DROP FUNCTION IF EXISTS toDecimal// +CREATE + FUNCTION toDecimal(mymoneymoney VARCHAR(32)) + RETURNS DECIMAL(12,6) + READS SQL DATA + BEGIN + /* Converts a MyMoneyMoney numerator/denominator string to a decimal number */ + DECLARE result DECIMAL (12,6); + SELECT SUBSTRING_INDEX(mymoneymoney, '/', 1) / SUBSTRING_INDEX(mymoneymoney, '/', -1) INTO result; + RETURN result; + END +// +delimiter ; + +delimiter // +DROP FUNCTION IF EXISTS cashBalance// +CREATE + FUNCTION cashBalance(acctId VARCHAR(32)) + RETURNS DECIMAL(12,2) + READS SQL DATA + BEGIN + /* Returns the cash balance as of today of an account specified by internal id.*/ + /* to determine id - SELECT id FROM kmmAccounts WHERE accountName = 'whatever'; + Sample usage - SELECT cashBalance('A000001'); */ + DECLARE result DECIMAL (12,2); + SELECT SUM(toDecimal(shares)) INTO result + FROM kmmSplits + WHERE accountId = acctId + AND postDate <= NOW() + AND txType = 'N'; + RETURN result; + END +// +delimiter ; + +delimiter // +DROP PROCEDURE IF EXISTS listBalances// +CREATE + PROCEDURE listBalances(IN parent varchar(32)) + READS SQL DATA + BEGIN + /* Lists the balances of all accounts subsidiary to a named account. NOTE: not recursive + Sample usage: - CALL listBalances('Asset'); */ + SELECT accountName, cashBalance(id) FROM kmmAccounts where parentId = + (SELECT id from kmmAccounts WHERE accountName = parent) + ORDER by 1; + END +// +delimiter ; + +delimiter // +DROP FUNCTION IF EXISTS latestPrice// +CREATE + FUNCTION latestPrice(secId VARCHAR(32)) + RETURNS DECIMAL(12,6) + READS SQL DATA + BEGIN + /* Returns the latest price for a security identified by internal id. */ + /* to determine id - SELECT id FROM kmmSecurities WHERE name = 'whatever'; */ + DECLARE result DECIMAL (12,6); + SELECT toDecimal(price) INTO result + FROM kmmPrices WHERE fromId = secId AND priceDate = + (SELECT MAX(priceDate) FROM kmmPrices WHERE fromId = secId); + RETURN result; +END +// +delimiter ; + +delimiter // +DROP FUNCTION IF EXISTS shareBalance// +CREATE + FUNCTION shareBalance(acctId VARCHAR(32)) + RETURNS DECIMAL(12,6) + READS SQL DATA + BEGIN + /* Returns the share balance for an Stock account identified by internal id. + NOTE: similar to cashBalance but with greater precision */ + DECLARE result DECIMAL (12,6); + SELECT SUM(toDecimal(shares)) INTO result + FROM kmmSplits WHERE accountId = acctId AND txType = 'N'; + RETURN result; + END +// +delimiter ; + +delimiter // +DROP FUNCTION IF EXISTS valuation// +CREATE + FUNCTION valuation(acctId VARCHAR(32)) + RETURNS DECIMAL(12,2) + READS SQL DATA + BEGIN + /* Returns the current value of a Stock account identified by internal id */ + DECLARE result DECIMAL(12,2); + DECLARE secId VARCHAR(32); + SELECT currencyId FROM kmmAccounts WHERE id = acctId INTO secId; + SELECT shareBalance(acctId) * latestPrice(secId) INTO result; + RETURN result; + END +// +delimiter ; + + +delimiter // +DROP PROCEDURE IF EXISTS listValues// +CREATE PROCEDURE listValues(IN parent varchar(32)) + READS SQL DATA + BEGIN + /* Lists the current values of all stocks subsidiary to a named Investment account. NOTE: not recursive */ + SELECT parent AS 'Portfolio'; + SELECT accountName, valuation(id) AS 'Value' FROM kmmAccounts where parentId = + (SELECT id from kmmAccounts WHERE accountName = parent) + ORDER by 1; + SELECT SUM(valuation(id)) AS 'Total Value' FROM kmmAccounts where parentId = + (SELECT id from kmmAccounts WHERE accountName = parent); + END +// +delimiter ; + +delimiter // +DROP FUNCTION IF EXISTS payeeName// +CREATE + FUNCTION payeeName(payeeId VARCHAR(32)) + RETURNS MEDIUMTEXT + READS SQL DATA + BEGIN + /* Returns payee name from id, with NULL test */ + DECLARE result MEDIUMTEXT; + IF payeeId IS NULL THEN SET result = 'Empty Payee'; + ELSE SELECT name FROM kmmPayees WHERE id = payeeId INTO result; + END IF; + RETURN result; + END +// +delimiter ; + +delimiter // +DROP FUNCTION IF EXISTS categoryName// +CREATE + FUNCTION categoryName(categoryId VARCHAR(32)) + RETURNS MEDIUMTEXT + READS SQL DATA + BEGIN + /* Returns fully qualified category name from its id */ + DECLARE result MEDIUMTEXT; + DECLARE thisName MEDIUMTEXT; + DECLARE parent VARCHAR(32); + IF categoryId IS NULL THEN RETURN 'Empty Category'; + END IF; + SELECT accountName from kmmAccounts WHERE id = categoryId INTO result; + SELECT parentId from kmmAccounts WHERE id = categoryId INTO parent; + WHILE parent IS NOT NULL DO + SELECT accountName from kmmAccounts WHERE id = parent INTO thisName; + SET result = CONCAT(thisName, ':', result); + SELECT parentId from kmmAccounts WHERE id = parent INTO parent; + END WHILE; + RETURN result; + END +// +delimiter ; + +/* some useful functions re tax */ +DROP VIEW IF EXISTS taxCats; +CREATE VIEW taxCats AS SELECT kvpId AS accountId FROM kmmKeyValuePairs WHERE kvpKey = 'Tax' AND kvpData = 'Yes'; +DROP VIEW IF EXISTS taxSplits; +CREATE VIEW taxSplits AS SELECT accountId, payeeId, postDate, CAST(toDecimal(value) AS decimal(12,2)) AS Amount FROM kmmSplits WHERE txType = 'N' AND accountId IN (SELECT * FROM taxCats); + + +/* Sample: generate a tax report for UK yesr 08-09. + Sorted by payee within Category */ +DROP VIEW IF EXISTS taxReport; +CREATE VIEW taxReport AS SELECT categoryName(accountId) AS Account, payeeName(payeeId) As Payee, DATE_FORMAT(postDate, '%d/%m/%y') As Date, ABS(Amount) AS Amount FROM taxSplits WHERE postDate > "2008-04-05" and postDate < "2009-04-06" ORDER BY 1, 2, 3; + diff --git a/contrib/kmm-safe b/contrib/kmm-safe new file mode 100755 index 0000000..2519565 --- /dev/null +++ b/contrib/kmm-safe @@ -0,0 +1,49 @@ +#!/bin/bash +# +# make a copy of KMyMoney files in a 'safe' directory whenever +# the contents of the orignal changed since the last run of this program. +# In order to make it work for you, please modify the parameters +# and erase the line following it. +# +# in order to automate the process, I entered the following two lines +# into my crontab using 'crontab -e' +# +# # make a copy of the valuable KMyMoney data every 20 minutes +# */20 * * * * /home/thb/bin/kmm-safe +# +# (C) 2005 by Thomas Baumgart (ipwizard at users.sourceforge.net) + +# DATA_FILES="$HOME/thb.xml $HOME/thb.kmy" +DATA_FILES="$HOME/thb.kmy" +SAFE_DIR="$HOME/kmymoney-safe" +DATE_FORM="%Y-%m-%d-%H-%M-%S" + +echo "Please configure to your likings and comment these two lines" +exit 1 + +for i in $DATA_FILES; do + NEWFN=$SAFE_DIR/`basename $i`-`date +$DATE_FORM` + OLDFN=$SAFE_DIR/`basename $i`-last + + # check if we need to keep a copy + NEEDSAVE=0 + if test ! -e $OLDFN; then + NEEDSAVE=1 + fi + if test $NEEDSAVE -eq 0; then + CS1=`md5sum $i | cut -d' ' -f1` + CS2=`md5sum $OLDFN | cut -d' ' -f1` + if test $CS1 != $CS2; then + NEEDSAVE=1 + fi + fi + + if test $NEEDSAVE -eq 1; then + cp $i $NEWFN + if test -e $OLDFN; then + rm $OLDFN + fi + ln -s $NEWFN $OLDFN + fi +done + diff --git a/contrib/mysqlcrypt.sh b/contrib/mysqlcrypt.sh new file mode 100644 index 0000000..b04525b --- /dev/null +++ b/contrib/mysqlcrypt.sh @@ -0,0 +1,99 @@ +# mysqlcrypt.sh +# This shell script will run KMyMoney in a MySql database +# and uses the MySql dump program to maintain a copy of the data. +# Additionally, another copy is written to a backup +# directory before running KMyMoney. These backups will be deleted after a +# user-specified number of days. + +# Optionally, these data files may be encrypted. +# For encryption, it is necessary that you have the 'gpg' program installed, +# and have set up a key identified by an email address (which may be a pseudo address). +# See 'man gpg' for more info. The kgpg program will help set up these keys. +# DO NOT forget the password associated with gpg; you will need it to access your data. + +# Optionally, the data can be removed from the database after KMyMoney finishes, +# and reloaded next time you run. + +# It is assumed that your logon user name has the necessary database permissions. + +# Please set the following variables to your requirements +MYDIR=$HOME/money # directory where the encrypted copy is to be held +BUDIR=$MYDIR/backup # directory where the backups should go; +FILE=myfin # name for the encrypted copy +DBNAME=KMyMoney # mysql datbase name +DROP=y # (y/n) - whether to delete info from database after running kmm +SILENT=n # if set to y, backups will be deleted silently, else you will be asked +CRYPTEMAIL=me@googlemail.com # delete this line if you don't want encrypted copies +declare -i KEEP=7 # number of days to keep backups +# end of user-changeable directives + +if [ ! -d $MYDIR ] ; then + mkdir $MYDIR; +fi +if [ ! -d $BUDIR ] ; then + mkdir $BUDIR; +fi + +if [ -z $CRYPTEMAIL ]; then + EFILE=${FILE}; +else + EFILE=${FILE}.gpg; +fi + +declare NOW=`date +%Y%m%d%H%M%S` + +if [ ! -f $MYDIR/$EFILE ] ; then + kdialog --warningcontinuecancel "A version of $FILE does not exist in $MYDIR.\nWhen KMyMoney starts, please open or create a file and use the 'File/Save as Database' function." + if [ $? -ne 0 ]; then + exit; + fi + KMMCMD=-n; +else + KMMCMD=sql://$USER@localhost/$DBNAME?driver=QMYSQL3 + # backup file + cp $MYDIR/$EFILE $BUDIR/$NOW$EFILE + LOAD=y + mysql -e "use $DBNAME;" 2>/dev/null + if [ $? -eq 0 ]; then + kdialog --warningyesno "A $DBNAME database exists. Do you wish to run with this?\n If not, the database will be reloaded from the encrypted file" + if [ $? -eq 0 ]; then # replied yes + LOAD=n + fi; + fi; + if [ $LOAD = y ]; then + echo "Reloading from file" + if [ -z $CRYPTEMAIL ]; then + mysql <$MYDIR/$EFILE; + else + gpg --decrypt $MYDIR/$EFILE |mysql; + fi; + fi; +fi +#run kmymoney +kmymoney $KMMCMD +mysqldump --databases -R $DBNAME >$MYDIR/$FILE +if [ ! -z $CRYPTEMAIL ]; then + rm -f $MYDIR/$EFILE + gpg -e -r $CRYPTEMAIL $MYDIR/$FILE + rm $MYDIR/$FILE; +fi + +case ${DROP:0:1} in + y | Y) mysql -e "drop database KMyMoney;";; +esac + +# delete outdated backup files +cd $BUDIR +for i in `find . -name "*${EFILE}" -ctime +${KEEP}`; do + case ${SILENT:0:1} in + y | Y) ANSWER=y + ;; + *) read -p "Delete $i?" ANSWER + ;; + esac + case ${ANSWER:0:1} in + y | Y) echo "Deleting $i!" + rm $i + ;; + esac +done diff --git a/contrib/splitup-kde-chunk-online b/contrib/splitup-kde-chunk-online new file mode 100755 index 0000000..53003cc --- /dev/null +++ b/contrib/splitup-kde-chunk-online @@ -0,0 +1,88 @@ +#!/usr/bin/perl +# +# split up an HTML file generated with e.g. +# +# /opt/kde3/bin/meinproc --check \ +# --stylesheet `dirname $(KDE_XSL_STYLESHEET)`/kde-chunk-online.xsl \ +# $(srcdir)/index.docbook -o index.xml; +# +# into several HTML files. While processing the input file - which +# must be named index.xml - replace the following occurences: +# +# source destination +# --------------------------------------------------------------------------- +# HEAD/common ../common +# Search -literally nothing- +# docs.kde.org Home +# +# The script should be started in the directory where the file index.xml +# is located. The output files will be generated in the same directory. +# +# (C) 2007,2009 by Thomas Baumgart (ipwizard at users.sourceforge.net) +# +#*************************************************************************** +#* 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. * +#***************************************************************************/ + + +sub endFile +{ + close OUT; + $fileIdx--; + if($fileIdx > 0) { + open(OUT, ">> $fname[$fileIdx]") or die("Unable to open file"); + } +} + +sub startFile +{ + $fileIdx++; + my $node = shift; + $node =~ /FILENAME filename="(.*)"/; + my $name = $1; + $fname[$fileIdx] = $name; + open(OUT, "> $fname[$fileIdx]") or die("Unable to open file"); +} + +sub processLine +{ + my $line = shift; + # ......... + if($line =~ /(.*)(<\/FILENAME>)(.*)/) { + my $s = $1; + my $e = $3; + processLine($s); + endFile(); + processLine($e); + } + # ......... + elsif($line =~ /(.*)()(.*)/) { + my $s = $1; + my $f = $2; + my $e = $3; + processLine($s); + startFile($f); + processLine($e); + } + else { + # replace HEAD/common with ../common + $line =~ s#/HEAD/common#../common#g; + # don't show access to search form + $line =~ s#Search##g; + # don't link to docs.kde.org + $line =~ s#docs.kde.org#Home#g; + print OUT "$line\n"; + } +} + +$fileIdx = 0; +open(IN, "< index.xml"); +while() { + chomp($_); + my $line = $_; + processLine($line); +} +close IN; diff --git a/contrib/viewxml.sh b/contrib/viewxml.sh new file mode 100755 index 0000000..cd1ef17 --- /dev/null +++ b/contrib/viewxml.sh @@ -0,0 +1,45 @@ +# A bash script to view a temporary copy of a KMyMoney XML file in your favourite editor +# (works with some gnucash files too!) + +# Usage:- viewxml [filename] + +# Save this script somewhere in your path and remember to apply execute permissions (chmod a+x viewxml) +# Set the following variables as required +TMPDIR=/tmp # a temporary directory for storing the file copy +EDITOR=kate # your editor of choice +WIPE='rm -f' # command to get rid of the temporary file copy (could be replaced with a shredder or something) +# + +declare -i TYPE + +if [ -z $1 ]; then + FILE=`kdialog --getopenfilename . '*.*'`; +else + FILE=$1; +fi + +TYPE=0 # default type, gzipped file +read -n 14 <$FILE HEAD +if [ "$HEAD" = "-----BEGIN PGP" ]; then + TYPE=1; # encrypted file +elif [ "$HEAD" = "$TMPDIR/$BASENAME;; + 2) echo $BASENAME is plaintext + cp $FILE $TMPDIR/$BASENAME;; +esac + +$EDITOR $TMPDIR/$BASENAME + +$WIPE $TMPDIR/$BASENAME + + -- cgit v1.2.3