GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Static 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
 
- Public Member Functions inherited from python-bindings.gnucash_core.GnuCashCoreClass
def do_lookup_create_oo_instance
 

Static Public Member Functions

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 62 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 76 of file gnucash_core.py.

76 
77  force_new= False):
78  """A convenient constructor that allows you to specify a book URI,
79  begin the session, and load the book.
80 
81  This can give you the power of calling
82  qof_session_new, qof_session_begin, and qof_session_load all in one!
83 
84  book_uri can be None to skip the calls to qof_session_begin and
85  qof_session_load, or it can be a string like "file:/test.xac"
86 
87  qof_session_load is only called if is_new is set to False
88 
89  is_new is passed to qof_session_begin as the argument create,
90  and force_new as the argument force. Is_new will create a new
91  database or file; force will force creation even if it will
92  destroy an existing dataset.
93 
94  ignore_lock is passed to qof_session_begin's argument of the
95  same name and is used to break an existing lock on a dataset.
96 
97 
98 
99  This function can raise a GnuCashBackendException. If it does,
100  you don't need to cleanup and call end() and destroy(), that is handled
101  for you, and the exception is raised.
102  """
103  GnuCashCoreClass.__init__(self)
104  if book_uri is not None:
105  try:
106  self.begin(book_uri, ignore_lock, is_new, force_new)
107  # Take care of backend inconsistency
108  # New xml file can't be loaded, new sql store
109  # has to be loaded before it can be altered
110  # Any existing store obviously has to be loaded
111  # More background: https://bugzilla.gnome.org/show_bug.cgi?id=726891
112  if book_uri[:3] != "xml" or not is_new:
113  self.load()
114  except GnuCashBackendException, backend_exception:
115  self.end()
116  self.destroy()
117  raise

Member Function Documentation

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

Definition at line 131 of file gnucash_core.py.

132  def generate_errors(self):
133  """A generator that yields any outstanding QofBackend errors
134  """
135  while self.get_error() is not ERR_BACKEND_NO_ERR:
136  error = self.pop_error()
137  yield error
def python-bindings.gnucash_core.Session.pop_all_errors (   self)
Returns any accumulated qof backend errors as a tuple

Definition at line 138 of file gnucash_core.py.

139  def pop_all_errors(self):
140  """Returns any accumulated qof backend errors as a tuple
141  """
142  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 118 of file gnucash_core.py.

119  def raise_backend_errors(self, called_function="qof_session function"):
120  """Raises a GnuCashBackendException if there are outstanding
121  QOF_BACKEND errors.
122 
123  set called_function to name the function that was last called
124  """
125  errors = self.pop_all_errors()
126  if errors != ():
128  "call to %s resulted in the "
129  "following errors, %s" % (called_function, backend_error_dict[errors[0]]),
130  errors )
def python-bindings.gnucash_core.Session.raise_backend_errors_after_call (   function)
static
A function decorator that results in a call to
raise_backend_errors after execution.

Definition at line 145 of file gnucash_core.py.

146  def raise_backend_errors_after_call(function):
147  """A function decorator that results in a call to
148  raise_backend_errors after execution.
149  """
150  def new_function(self, *args):
151  return_value = function(self, *args)
152  self.raise_backend_errors(function.__name__)
153  return return_value
154  return new_function

The documentation for this class was generated from the following file: