Python Bindings and Backends

Mike Evans mikee at saxicola.idps.co.uk
Sat Nov 13 05:25:52 EST 2010


On Friday November 12 2010 22:17:41 John Ralls wrote:
> I noticed, while working on the python bindings, that it pulls in and
> attempts to init the xml and dbi backends. That's wrong for several
> reasons which I've documented in
> https://bugzilla.gnome.org/show_bug.cgi?id=634712.
> 
> I've written a patch to remove the gnc_module_backend_init_foo() calls from
> gnucash_core.i and the associated stuff from the Makefile. It works with
> simple_test.py in example_scripts, but I'd like at least one of the
> regular python users to test-drive it before I commit it.
> 
> Regards,
> John Ralls
> 
> _______________________________________________
Hi John

Bad news I'm afraid, your patch breaks my script with the following output:

/usr/local/lib/python2.6/site-packages/gnucash/function_class.py:49: 
DeprecationWarning: object.__new__() takes no parameters
  return super(ClassFromFunctions, cls).__new__(cls, *args, **kargs)
Cannot create session.  A lockfile may exist or you have GnuCash open.
Enter y to open anyway: y
Unknown error occurred. Stopping
call to begin resulted in the following errors, (3,)

I'm not sure what the error number means in this case.  I know that a (7,) is 
due to a locked database.

The script portion causing the error is:

try:
  session = Session('xml:///home/$PATH_TO_FILE', False, False)
except GnuCashBackendException as (errno):
  #print "{0}".format(errno)
  print "Cannot create session.  A lockfile may exist or you have GnuCash 
open."
  resp = raw_input("Enter y to open anyway: ")
  if not resp =='y':
    print "Quitting on user response.  Database was not changed."
    quit()
  else:
    try:
      session = Session('xml:///home/$PATH_TO_FILE', False, True)
    except GnuCashBackendException as (errno):
      print "Unknown error occurred. Stopping"
      print "{0}".format(errno)
      quit(1)

Definitely worked before applying the patch and there is no lockfile present.

The script simple_test.py also fails:

/usr/local/lib/python2.6/site-packages/gnucash/function_class.py:49: 
DeprecationWarning: object.__new__() takes no parameters
  return super(ClassFromFunctions, cls).__new__(cls, *args, **kargs)
Traceback (most recent call last):
  File "simple_test.py", line 8, in <module>
    session = Session("xml://%s" % FILE_1, True)
  File "/usr/local/lib/python2.6/site-packages/gnucash/gnucash_core.py", line 
96, in __init__
    self.begin(book_uri, ignore_lock, is_new, force_new)
  File "/usr/local/lib/python2.6/site-packages/gnucash/gnucash_core.py", line 
137, in new_function
    self.raise_backend_errors(function.__name__)
  File "/usr/local/lib/python2.6/site-packages/gnucash/gnucash_core.py", line 
115, in raise_backend_errors
    errors )
gnucash.gnucash_core.GnuCashBackendException: call to begin resulted in the 
following errors, (3,)

My System is Fedora12.

Mike E

-- 
GPG Key: 1024D/050895C2
Keyserver: http://pgp.mit.edu/          
Search String: 0x050895C2


More information about the gnucash-devel mailing list