Rob Walker <[EMAIL PROTECTED]> writes:
> rats. is this one thing making it tons more difficult than it needs
> to be? if i could cat the gnucash files and _understand_ them, I
> would use standard tools and perl or sed or python or whatever to
> get it working. is there a simple format for gnucash that i could
> write with text tools, and then import it later?
Well, I don't have time to go into great detail ATM, but there is the
"text-export" function on the extensions menu. It dumps the entire
account group as a set of scheme forms, but there's nothing (yet) to
read them back in.
However, if all you want to do is to schedule an event or two, and
you're willing to make the assumption that you'll just never fire them
when you're running gnucash (i.e. follow the "don't do that"
principle), then you could probably get simple automated transactions
working for yourself with reasonable effort.
First, write a scheme script that does what you want. It might look
something like the one below (this code is not only untested, it's
just psuedocode; I'm sure I'm using functions we haven't written yet,
though they wouldn't be *that* hard to write):
(with-gnucash-account-group-file "foo.gnc"
(lambda (group)
(let ((transaction (gnc:create-transaction)))
(if (not (pointer-token-null? transaction))
(begin
(gnc:transaction-set-date transaction ...)
(gnc:transaction-set-description transaction ...)
;;; Create and add splits here...
;;; etc.
(gnc:save-account-group group))))))
Of course, it would be nice to put some friendlier wrapper on this so
you could just say something like:
(gnc:add-transaction-to-file "foo.gnc"
(gnc:simple-build-transaction
"1999-10-12"
"Some description"
"MainChecking"
'(("Some split memo" "MegaBank" 12.00)
("Some other split" ("Auto" "Fuel") -4.00))))
and have gnc:add-transaction-to-file be smart enough to DTRT if
gnc:simple-build-transaction returned false because it couldn't find
the accounts mentioned by name, or some other error occurred. Note
the use of a list to indicate a non-top-level account. As a
convenience I figured you could let top level accounts just be named
with plain strings rather than having to be pedantic like
'("MainChecking").
You can then test parts of your code by editing extensions.scm to
stick them on the extensions menu.
Next, for a more elegant solution (I'll mention the ugly hack later),
you'd need a "--run-script script" function. Right now, if you start
up normally, you get the GUI. If you use GNC_RUN_AS_SHELL=t, you get
a guile prompt where all of the relevant gnucash code hasn't been
loaded yet. What we'd probably want is for --run-script to load
everything normally, not start the gui, call the indicated script, and
then quit.
Once you had this working, then you could use "at" or cron to schedule
it
echo gnucash --run-script /some/where/myscript | \
at now + 5 hours
All this sounds complicated, but I don't actually think it would be
that hard. Most of it is fairly straightforward enhancements to the
stuff we already have, and you could potentially even skip the
--run-script addition if you were willing to put more code into
"myscript". Without looking, I think you'd need something similar to
this:
(primitive-load (getenv "GNC_BOOTSTRAP_SCM"))
(gnc:load "startup.scm")
;; ...
;; your code here
Then running it would look something like
echo "GNC=RUN_AS_SHELL=t gnucash -l /some/where/myscript | \
at now + 5 hours
Actually, though, this probably won't quite do it. There is still
some work to be done to separate out the GUI bits from the non-gui
bits during the startup process. For example, I think there are files
loaded at the top of main.scm, before it drops off into GUI
never-never land, that you'd want to load when running your script,
but right now you can't get them by just loading main.scm because
you'll never get control back. If we had the --run-script option, we
could just have main.scm pay attention to that. As an
ugly-short-term-hack(TM) hack you could just paste the bits of
main.scm that you decide you need into your script.
Am I just rambling, or does all this make some sense? The overall
gist is that the ability to do something "simple" event-wise wouldn't
be a monumental task, though it wouldn't be trivial either. The more
elegant the solution (and the more useful --- --run-script is
something we're going to want eventually anyhow), the more work
required. The good thing is that if you get the "simple" solution up
and running, it's a notable chunk of the the mega-solution.
I gues I went into detail anyway...
> ipc?
Most likely.
--
Rob Browning <[EMAIL PROTECTED]> PGP=E80E0D04F521A094 532B97F5D64E3930
--
Gnucash Developer's List
To unsubscribe send empty email to: [EMAIL PROTECTED]