GnuCash 2.4.99
Public Member Functions
python-bindings::gnucash_core::Session Class Reference
Inheritance diagram for python-bindings::gnucash_core::Session:
python-bindings::gnucash_core::GnuCashCoreClass

Public Member Functions

def __init__
def raise_backend_errors
def generate_errors
def pop_all_errors
def raise_backend_errors_after_call

Detailed Description

A GnuCash book editing session

To commit changes to the session you may need to call save,
(this is always the case with the file backend).

When you're down with a session you may need to call end()

Every Session has a Book in the book attribute, which you'll definitely
be interested in, as every GnuCash entity (Transaction, Split, Vendor,
Invoice..) is associated with a particular book where it is stored.

Definition at line 60 of file gnucash_core.py.


Constructor & Destructor Documentation

def python-bindings::gnucash_core::Session::__init__ (   self,
  book_uri = None,
  ignore_lock = False,
  is_new = False,
  force_new = False 
)
A convenient constructor that allows you to specify a book URI,
begin the session, and load the book.

This can give you the power of calling
qof_session_new, qof_session_begin, and qof_session_load all in one!

book_uri can be None to skip the calls to qof_session_begin and
qof_session_load, or it can be a string like "file:/test.xac"

qof_session_load is only called if is_new is set to False

is_new is passed to qof_session_begin as the argument create,
and force_new as the argument force. Is_new will create a new
database or file; force will force creation even if it will
destroy an existing dataset.

ignore_lock is passed to qof_session_begin's argument of the
same name and is used to break an existing lock on a dataset.



This function can raise a GnuCashBackendException. If it does,
you don't need to cleanup and call end() and destroy(), that is handled
for you, and the exception is raised.

Definition at line 73 of file gnucash_core.py.

00075                                   :
00076         """A convenient constructor that allows you to specify a book URI,
00077         begin the session, and load the book.
00078 
00079         This can give you the power of calling
00080         qof_session_new, qof_session_begin, and qof_session_load all in one!
00081 
00082         book_uri can be None to skip the calls to qof_session_begin and
00083         qof_session_load, or it can be a string like "file:/test.xac"
00084 
00085         qof_session_load is only called if is_new is set to False
00086 
00087         is_new is passed to qof_session_begin as the argument create,
00088         and force_new as the argument force. Is_new will create a new
00089         database or file; force will force creation even if it will
00090         destroy an existing dataset.
00091 
00092         ignore_lock is passed to qof_session_begin's argument of the
00093         same name and is used to break an existing lock on a dataset.
00094 
00095 
00096 
00097         This function can raise a GnuCashBackendException. If it does,
00098         you don't need to cleanup and call end() and destroy(), that is handled
00099         for you, and the exception is raised.
00100         """
00101         GnuCashCoreClass.__init__(self)
00102         if book_uri is not None:
00103             try:
00104                 self.begin(book_uri, ignore_lock, is_new, force_new)
00105                 if not is_new:
00106                     self.load()
00107             except GnuCashBackendException, backend_exception:
00108                 self.end()
00109                 self.destroy()
00110                 raise


Member Function Documentation

def python-bindings::gnucash_core::Session::generate_errors (   self)
A generator that yields any outstanding QofBackend errors

Definition at line 124 of file gnucash_core.py.

00125                              :
00126         """A generator that yields any outstanding QofBackend errors
00127         """
00128         while self.get_error() is not ERR_BACKEND_NO_ERR:
00129             error = self.pop_error()
00130             yield error

def python-bindings::gnucash_core::Session::pop_all_errors (   self)
Returns any accumulated qof backend errors as a tuple

Definition at line 131 of file gnucash_core.py.

00132                             :
00133         """Returns any accumulated qof backend errors as a tuple
00134         """
00135         return tuple( self.generate_errors() )

def python-bindings::gnucash_core::Session::raise_backend_errors (   self,
  called_function = "qof_session function" 
)
Raises a GnuCashBackendException if there are outstanding
QOF_BACKEND errors.

set called_function to name the function that was last called

Definition at line 111 of file gnucash_core.py.

00112                                                                           :
00113         """Raises a GnuCashBackendException if there are outstanding
00114         QOF_BACKEND errors.
00115 
00116         set called_function to name the function that was last called
00117         """
00118         errors = self.pop_all_errors()
00119         if errors != ():
00120             raise GnuCashBackendException(
00121                 "call to %s resulted in the "
00122                 "following errors, %s" % (called_function, backend_error_dict[errors[0]]),
00123                 errors )

def python-bindings::gnucash_core::Session::raise_backend_errors_after_call (   function)
A function decorator that results in a call to
raise_backend_errors after execution.

Definition at line 138 of file gnucash_core.py.

00139                                                  :
00140         """A function decorator that results in a call to
00141         raise_backend_errors after execution.
00142         """
00143         def new_function(self, *args):
00144             return_value = function(self, *args)
00145             self.raise_backend_errors(function.__name__)
00146             return return_value
00147         return new_function


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines