diff --git a/bindings/python/example_scripts/account_analysis.py b/bindings/python/example_scripts/account_analysis.py index 135d2e60ef..fe24a2e219 100644 --- a/bindings/python/example_scripts/account_analysis.py +++ b/bindings/python/example_scripts/account_analysis.py @@ -35,7 +35,7 @@ from math import log10 import csv # gnucash imports -from gnucash import Session, GncNumeric, Split +from gnucash import Session, GncNumeric, Split, SessionOpenMode # Invoke this script like the following example # $ python3 account_analysis.py gnucash_file.gnucash \ @@ -173,7 +173,7 @@ def main(): account_path = argv[8:] - gnucash_session = Session(gnucash_file, is_new=False) + gnucash_session = Session(gnucash_file, SessionOpenMode.SESSION_NORMAL_OPEN) root_account = gnucash_session.book.get_root_account() account_of_interest = account_from_path(root_account, account_path) diff --git a/bindings/python/example_scripts/gncinvoice_jinja.py b/bindings/python/example_scripts/gncinvoice_jinja.py index f44f308ab2..bfa7c09a58 100755 --- a/bindings/python/example_scripts/gncinvoice_jinja.py +++ b/bindings/python/example_scripts/gncinvoice_jinja.py @@ -39,6 +39,7 @@ try: import str_methods import jinja2 from gncinvoicefkt import * + from gnucash import SessionOpenMode except ImportError as import_error: print("Problem importing modules.") print(import_error) @@ -137,7 +138,7 @@ def main(argv=None): print("or file://filename") print("or mysql://user:password@host/databasename") print() - print("-f force open = ignore lock") + print("-f force open = ignore lock (read only)") print("-l list all invoices") print("-h or --help for this help") print("-I ID use invoice ID") @@ -150,8 +151,15 @@ def main(argv=None): # Try to open the given input try: - print("Opening", input_url, ".") - session = gnucash.Session(input_url, ignore_lock=ignore_lock) + print( + "Opening", input_url, " (ignore-lock = read-only)." if ignore_lock else "." + ) + session = gnucash.Session( + input_url, + SessionOpenMode.SESSION_READ_ONLY + if ignore_lock + else SessionOpenMode.SESSION_NORMAL_OPEN, + ) except Exception as exception: print("Problem opening input.") print(exception) diff --git a/bindings/python/example_scripts/latex_invoices.py b/bindings/python/example_scripts/latex_invoices.py index 2937c980a1..c29922e05d 100644 --- a/bindings/python/example_scripts/latex_invoices.py +++ b/bindings/python/example_scripts/latex_invoices.py @@ -64,6 +64,7 @@ try: from gnucash.gnucash_business import Customer, Employee, Vendor, Job, \ Address, Invoice, Entry, TaxTable, TaxTableEntry, GNC_AMT_TYPE_PERCENT, \ GNC_DISC_PRETAX + from gnucash import SessionOpenMode import locale except ImportError as import_error: print("Problem importing modules.") @@ -236,7 +237,12 @@ def main(argv=None): # Try to open the given input try: - session = gnucash.Session(input_url,ignore_lock=ignore_lock) + session = gnucash.Session( + input_url, + SessionOpenMode.SESSION_READ_ONLY + if ignore_lock + else SessionOpenMode.SESSION_NORMAL_OPEN, + ) except Exception as exception: print("Problem opening input.") print(exception) diff --git a/bindings/python/example_scripts/new_book_with_opening_balances.py b/bindings/python/example_scripts/new_book_with_opening_balances.py index df2d29ae7a..3a2d04e7bb 100644 --- a/bindings/python/example_scripts/new_book_with_opening_balances.py +++ b/bindings/python/example_scripts/new_book_with_opening_balances.py @@ -28,7 +28,8 @@ # @author Mark Jenkins, ParIT Worker Co-operative # @ingroup python_bindings_examples -from gnucash import Session, Account, Transaction, Split, GncNumeric +from gnucash import ( + Session, Account, Transaction, Split, GncNumeric, SessionOpenMode) from gnucash.gnucash_core_c import \ GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT, \ ACCT_TYPE_ASSET, ACCT_TYPE_BANK, ACCT_TYPE_CASH, ACCT_TYPE_CHECKING, \ @@ -299,8 +300,8 @@ def main(): #have everything in a try block to unable us to release our hold on stuff to the extent possible try: - original_book_session = Session(argv[1], is_new=False) - new_book_session = Session(argv[2], is_new=True) + original_book_session = Session(argv[1], SessionOpenMode.SESSION_NORMAL_OPEN) + new_book_session = Session(argv[2], SessionOpenMode.SESSION_NEW_STORE) new_book = new_book_session.get_book() new_book_root = new_book.get_root_account() diff --git a/bindings/python/example_scripts/rest-api/gnucash_rest.py b/bindings/python/example_scripts/rest-api/gnucash_rest.py index 51c75eb096..5334471396 100644 --- a/bindings/python/example_scripts/rest-api/gnucash_rest.py +++ b/bindings/python/example_scripts/rest-api/gnucash_rest.py @@ -68,6 +68,8 @@ from gnucash import \ from gnucash import \ INVOICE_IS_PAID +from gnucash import SessionOpenMode + app = Flask(__name__) app.debug = True @@ -1884,7 +1886,7 @@ for option, value in options: #start gnucash session base on connection string argument if is_new: - session = gnucash.Session(arguments[0], is_new=True) + session = gnucash.Session(arguments[0], SessionOpenMode.SESSION_NEW_STORE) # seem to get errors if we use the session directly, so save it and #destroy it so it's no longer new @@ -1893,7 +1895,8 @@ if is_new: session.end() session.destroy() -session = gnucash.Session(arguments[0], ignore_lock=True) +# unsure about SESSION_BREAK_LOCK - it used to be ignore_lock=True +session = gnucash.Session(arguments[0], SessionOpenMode.SESSION_BREAK_LOCK) # register method to close gnucash connection gracefully atexit.register(shutdown) diff --git a/bindings/python/example_scripts/simple_book.py b/bindings/python/example_scripts/simple_book.py index 19ebb01865..0059ff64e8 100644 --- a/bindings/python/example_scripts/simple_book.py +++ b/bindings/python/example_scripts/simple_book.py @@ -5,13 +5,13 @@ # @ingroup python_bindings_examples import sys -from gnucash import Session +from gnucash import Session, SessionOpenMode # We need to tell GnuCash the data format to create the new file as (xml://) uri = "xml:///tmp/simple_book.gnucash" print("uri:", uri) -with Session(uri, is_new=True) as ses: +with Session(uri, SessionOpenMode.SESSION_NEW_STORE) as ses: book = ses.get_book() #Call some methods that produce output to show that Book works diff --git a/bindings/python/example_scripts/simple_business_create.py b/bindings/python/example_scripts/simple_business_create.py index bb00846df9..e0df30bb80 100644 --- a/bindings/python/example_scripts/simple_business_create.py +++ b/bindings/python/example_scripts/simple_business_create.py @@ -53,7 +53,7 @@ from os.path import abspath from sys import argv, exit import datetime from datetime import timedelta -from gnucash import Session, Account, GncNumeric +from gnucash import Session, Account, GncNumeric, SessionOpenMode from gnucash.gnucash_business import Customer, Employee, Vendor, Job, \ Address, Invoice, Entry, TaxTable, TaxTableEntry, GNC_AMT_TYPE_PERCENT, \ GNC_DISC_PRETAX @@ -70,7 +70,7 @@ if len(argv) < 2: try: - s = Session(argv[1], is_new=True) + s = Session(argv[1], SessionOpenMode.SESSION_NEW_STORE) book = s.book root = book.get_root_account() diff --git a/bindings/python/example_scripts/simple_invoice_insert.py b/bindings/python/example_scripts/simple_invoice_insert.py index eef4c03baa..ee1bbfb063 100644 --- a/bindings/python/example_scripts/simple_invoice_insert.py +++ b/bindings/python/example_scripts/simple_invoice_insert.py @@ -46,7 +46,7 @@ # @author Mark Jenkins, ParIT Worker Co-operative # @ingroup python_bindings_examples -from gnucash import Session, GUID, GncNumeric +from gnucash import Session, GUID, GncNumeric, SessionOpenMode from gnucash.gnucash_business import Customer, Invoice, Entry from gnucash.gnucash_core_c import string_to_guid from os.path import abspath @@ -86,7 +86,7 @@ def gnc_numeric_from_decimal(decimal_value): return GncNumeric(numerator, denominator) -s = Session(argv[1], is_new=False) +s = Session(argv[1], SessionOpenMode.SESSION_NORMAL_OPEN) book = s.book root = book.get_root_account() diff --git a/bindings/python/example_scripts/simple_session.py b/bindings/python/example_scripts/simple_session.py index 05da9487ba..daebfdf649 100644 --- a/bindings/python/example_scripts/simple_session.py +++ b/bindings/python/example_scripts/simple_session.py @@ -3,9 +3,11 @@ # @brief Example Script simple session # @ingroup python_bindings_examples -from gnucash import \ - Session, GnuCashBackendException, \ +from gnucash import ( + Session, GnuCashBackendException, + SessionOpenMode, ERR_BACKEND_LOCKED, ERR_FILEIO_FILE_NOT_FOUND +) FILE_1 = "/tmp/not_there.xac" FILE_2 = "/tmp/example_file.xac" @@ -19,7 +21,7 @@ except GnuCashBackendException as backend_exception: # create a new file, this requires a file type specification -with Session("xml://%s" % FILE_2, is_new=True) as session: +with Session("xml://%s" % FILE_2, SessionOpenMode.SESSION_NEW_STORE) as session: book = session.book root = book.get_root_account() diff --git a/bindings/python/example_scripts/simple_sqlite_create.py b/bindings/python/example_scripts/simple_sqlite_create.py index 7900c9534d..61675be089 100644 --- a/bindings/python/example_scripts/simple_sqlite_create.py +++ b/bindings/python/example_scripts/simple_sqlite_create.py @@ -3,11 +3,11 @@ # @brief Example Script simple sqlite create # @ingroup python_bindings_examples -from gnucash import Session, Account +from gnucash import Session, Account, SessionOpenMode from os.path import abspath from gnucash.gnucash_core_c import ACCT_TYPE_ASSET -s = Session('sqlite3://%s' % abspath('test.blob'), is_new=True) +s = Session('sqlite3://%s' % abspath('test.blob'), SessionOpenMode.SESSION_NEW_STORE) # this seems to make a difference in more complex cases s.save() diff --git a/bindings/python/example_scripts/simple_test.py b/bindings/python/example_scripts/simple_test.py index b8a1bed02e..7101823dfa 100644 --- a/bindings/python/example_scripts/simple_test.py +++ b/bindings/python/example_scripts/simple_test.py @@ -3,11 +3,12 @@ # @brief Creates a basic set of accounts and a couple of transactions # @ingroup python_bindings_examples -from gnucash import Session, Account, Transaction, Split, GncNumeric +from gnucash import ( + Session, Account, Transaction, Split, GncNumeric, SessionOpenMode) FILE_1 = "/tmp/example.gnucash" -with Session("xml://%s" % FILE_1, is_new=True) as session: +with Session("xml://%s" % FILE_1, SessionOpenMode.SESSION_NEW_STORE) as session: book = session.book root_acct = Account(book) @@ -80,4 +81,4 @@ with Session("xml://%s" % FILE_1, is_new=True) as session: trans1.CommitEdit() - trans2.CommitEdit() \ No newline at end of file + trans2.CommitEdit()