Re: GnuCash page on GO site



On Thu, 2004-02-26 at 16:13, Linas Vepstas wrote:
> On Mon, Feb 23, 2004 at 10:13:17PM +1100, msevior physics unimelb edu au was heard to remark:
> > >> > > 3/ reporting --
> > >> > Good idea.
> > >>
> > >> Note that reports mean different things to different people, and
> > >> that as a technology, its a *HUGE* bundle of requirements.
> > >
> > > Perhaps it is worth formally documenting them somewhere.  From your
> > > descriptions (template-editable-in-word-processor and
> > > database-fields-pulled-together) I don't see any reason it cannot be
> > > accomplished well.  I might even help code to such a project.
> > >
> > 
> > AbiWord certainly has the capability to do all this right now. 
> 
> I like that; one plan was to use the edit abilites in gtkhtml3 but
> that's not as nice as a "real" word processor, at least for printing.
> For reports that are meant to be web pages, then ... ?
> 

Just export your AbiWord doc to (X)HTML. The HTML exporter is very good
now.

Also since we will use libGSF the reports can be directly exported to
webDav enabled sites.

There are 3 ways you might want to use Abi in gnuCash. 

1. Just start up a standard AbiWord process and rely on the user to do
what they'd like with the report.

2. Embed our abiwidget in your application. Requires linking against the
full Abiword tree.

3. Embed the AbiWord bonobo control in your app.


> > I can show
> > you how to construct documents that use libgda to pull in content from
> > whatever data source you want for programmable fields laid out in tables.
> 
> My gut feel is that libgda offers the wrong abstractions. 
> Although gnucash data can be (is) represented as SQL, that's 
> the wrong place to work.  There's a lot of pulling things together
> that must happen before the data is reportable.  For example,
> computing account balances can be quite complicated; its not a
> simple sql query or a simple table lookup.
> 

This is not insurmountable. We can use our mail-merge fields or even
invent some new ones for gnuCash

Or if the document is static simply paste the results straight into it.

> I started work on "qof" (qof.sourceforge.net) to deal with this.
> I did not get any buy-in from the gda folks on this, though.
> 
> > Doing this in AbiWord has the extra benefit that users can fiddle with it
> > afterward, export them to lots of different formats, cut and paste them
> > into other documents, etc etc.
> 
> Yes, that is exactly what is wanted.  
> 
> Note, another requirement would be the ability to run the reports
> as a batch job, or as a cgi-bin. But this is for the future, no for 
> short term.  Something to think about.
> 

No problem either. AbiWord has a command-line interface and be run as a
document server. I wrote a nice little bit of code that can shows how
this works. See attachments.


> > I actually have a much smaller requirement for my own home-grown little
> > accounts/budgeting program. I'll use AbiWord to show how far each budget
> > catergory is ahead or behind it's projected value.
> 
> One project I'd like to see happen someday is a 'gnucash-simple'
> which would just go back to a very very very simple UI. 
> But that's another day.
> 

I need it now and am discovering the joys of python with libglade :-)

Martin

/*
 * Convert WordProcessor Files To plain Text using remotely running AbiWord-2.2
 * process via it's command line interface.
 *
 * Copyright (C) (2003) by Martin Sevior <msevior physics unimelb edu au>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * The program is fault tolerant and will report if a requested
 * file is not capable of being coverted.
 * 
 * It will also restart AbiWord if it does crash on the next invocation
 * of convertFileToText.
 *
 * Remove the demo main program if you want to use these functions in your
 * own programs.
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "ConvertToText.h"

static int m_iAbiRunning = -1;
static int m_iAbiPID = -1;
static FILE * m_AbiWritePipe;
static char m_szErrorFile[100];

/* Start the AbiWord process and set up pointers so we can communicate
 * with it.
 * Return 0 on success;
 */
static int startAbiRunning(void)
{
	char fullCommand[200];
	pid_t mypid;
	char pidName[40];
	struct stat myNameStat;
	int loop,iMyStat;
	FILE * fAbiPIDFile;
	fullCommand[0] = 0;
/*	
    Uncomment to debug

    strcat(fullCommand,"AbiWord-2.2 --plugin AbiCommand "); */
	strcat(fullCommand,"AbiWord-2.2 --plugin AbiCommand >& /dev/null ");
	fflush(stdout);
	m_AbiWritePipe = popen(fullCommand,"w");
	fflush(stdout);
	if(m_AbiWritePipe == NULL)
	{
		m_iAbiRunning = -1;
		return -1;
	}
	fullCommand[0] = 0;
	mypid=getpid();
	pidName[0] = 0;
	sprintf(pidName,"/tmp/abiconv_%d.txt",mypid);
	strcat(fullCommand,"writepid ");
	strcat(fullCommand,pidName);
/*	printf("File Name is %s \n",pidName); */
/*	printf("Full command is %s \n",fullCommand); */
	fflush(stdout);
	fprintf(m_AbiWritePipe,"%s \n",fullCommand);
	fflush(m_AbiWritePipe);
	iMyStat = -1;
	while((iMyStat == -1) && (loop < 1000))
	{
		iMyStat = stat(pidName,&myNameStat);
		if(iMyStat == 0)
		{
			if(myNameStat.st_size > 0)
			{
				break;
			}
		}
		usleep(100000);
	}
	if(iMyStat < 0)
	{
		m_iAbiRunning = -1;
		return -1;
	}
	fAbiPIDFile = fopen(pidName,"r");
	fscanf(fAbiPIDFile,"%d",&m_iAbiPID);
	fclose(fAbiPIDFile);
/*	printf("PID of remote AbiWord process is %d \n",m_iAbiPID); */
	unlink(pidName);
	m_iAbiRunning = 0;
	fprintf(m_AbiWritePipe,"server %s \n");
	fflush(m_AbiWritePipe);
	m_szErrorFile[0] = 0;
	sprintf(m_szErrorFile,"/tmp/AbiCommandError%d.txt",m_iAbiPID);
	printf("Error file is %s \n",m_szErrorFile);
	return 0;
}

/*
 * Returns 0 if the AbiWord process of PID given in our member variable
 * is running.
 * returns -1 if it isn't
 */
static int checkAbiIsRunning(void)
{
	char fullCommand[200];
	char szPID[40];
	FILE * psRes;
	fullCommand[0] = 0;
	szPID[0] = 0;
	sprintf(szPID,"%d",m_iAbiPID);
	sprintf(fullCommand,"ps %d ",m_iAbiPID);
	fflush(stdin);
	int iFound;
	psRes = popen(fullCommand,"r");
/*
 * Now read though all the output and look for our PID.
 */	
	iFound = -1;
	while ( !feof(psRes) && iFound == -1 )
	{
		fullCommand[0] = 0;
		fscanf(psRes,"%s",fullCommand);	
		if(strstr(fullCommand,szPID) != 0)
		{
			iFound = 0;
			break;
		}
	}
	pclose(psRes);
	if(iFound == 0)
	{
		m_iAbiRunning = 0;
		return 0;
	}
	m_iAbiRunning = -1;
	return -1;
}

/*
 * Looks to see if the conversion to the output file given by
 * outFile is completed.
 * It returns 0 if it's completed.
 * It returns -1 if it's not finished.
 * It returns -2 if The coversion was not successful.
 */
static int isConvertCompleted(const char * outFile)
{
	if(checkAbiIsRunning() == -1)
	{
		return -2;
	}
	struct stat myNameStat;
	int iMyStat;
	iMyStat = stat(outFile,&myNameStat);
	if(iMyStat == 0)
	{
		if(myNameStat.st_size > 0)
		{
			return 0;
		}
	}
	iMyStat = stat(m_szErrorFile,&myNameStat);
	if(iMyStat == 0)
	{
		return -3;
	}
	return -1;
}
/*
 * The function is fault tolerant and will report if a requested
 * file is not capable of being coverted.
 * 
 * It will also restart AbiWord if it does crash on the next invocation
 * of convertFileToText.
 *
 * Inputs: inFile - The path to the word processor file to be converted.
 *         outFile - The path to the file containing the plain text of the
 *                   word processor file.
 * The function blocks until the conversion is complete or until 
 * the conversion fails.
 * 
 * It returns 0 upon a successful conversion
 *    and -1 if the conversion fails.
 */
int convertFileToText(const char * inFile, const char * outFile)
{
	char fullCommand[200];
	int finished = -1;
	int iLoop = 0;
	if(m_iAbiRunning < 0)
	{
		startAbiRunning();
	}
	if(checkAbiIsRunning() < 0)
	{
		startAbiRunning();
		if(checkAbiIsRunning() < 0)
		{
			return -1;
		}
	}
	fullCommand[0] = 0;
	strcat(fullCommand,"converttotext ");
	strcat(fullCommand,inFile);
	if(outFile != NULL)
	{
		strcat(fullCommand," ");
		strcat(fullCommand,outFile);
	}
	fprintf(m_AbiWritePipe, "%s \n", fullCommand);
	fflush(m_AbiWritePipe);
	finished = -1;
	iLoop = 0;
	while(finished == -1 && (iLoop < 1000))
	{
		finished = isConvertCompleted(outFile);
		usleep(100000);
	}
	if(finished == -3)
	{
		unlink(m_szErrorFile);
		return -3;
	}
	if(iLoop >= 1000)
	{
/*		printf("Conversion timed out \n"); */
	}
	if(finished == 0)
	{
		return 0;
	}
	return -1;
}

/*
 * Call this method after all conversions have completed. Otherwise you'll 
 * have a runaway AbiWord-2.2 process.
 */
int finalizeConversions(void)
{
	struct stat myNameStat;
	int iMyStat;
	if(checkAbiIsRunning() == 0)
	{
		fprintf(m_AbiWritePipe,"%s","quit");
		fflush(m_AbiWritePipe);
		pclose(m_AbiWritePipe);
		m_iAbiRunning = -1;
		m_iAbiPID = 0;
		m_AbiWritePipe = NULL;
	}
	iMyStat = stat(m_szErrorFile,&myNameStat);
	if(iMyStat == 0)
	{
		unlink(m_szErrorFile);
	}
}

/*
 * make this #ifdef 0 if you want to link these functions into your
 * program.
 */
#if 1
int main (int argc, char *argv [])
{
	printf("Type: quit quit to exit this program \n");
	m_iAbiRunning = -1;
	m_iAbiPID = 0;
	int iQuit = -1;
	int isucc = -1;
	char inFile[100];
	char outFile[100];
	while(iQuit == -1)
	{
		printf("Convert: ");
		scanf("%s %s",&inFile,&outFile);
		if(strstr(inFile,"quit") != NULL)
		{
			iQuit = 0;
			finalizeConversions();
		}
		else
		{
			isucc = convertFileToText(inFile,outFile);
			if(isucc == 0)
			{
				printf("Conversion was successful \n");
			}
			else
			{
				printf("Conversion failed \n");
			}
		}
	}
	exit(0);
}
#endif
/*
 * ConvertFileToText using the AbiWord command line interface.
 *
 * Copyright (C) (2003) by Martin Sevior <msevior physics unimelb edu au>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */
#ifndef ABI_CONVERTTEXT_H
#define ABI_CONVERTTEXT_H

int  convertFileToText(const char * inFile, const char * outFile);
int  finalizeConversions(void);
#endif /* ABI_CONVERTTEXT_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]