diff --git a/src/bindings/python/fluxacct/accounting/bank_subcommands.py b/src/bindings/python/fluxacct/accounting/bank_subcommands.py index fa24299f..914ee13c 100644 --- a/src/bindings/python/fluxacct/accounting/bank_subcommands.py +++ b/src/bindings/python/fluxacct/accounting/bank_subcommands.py @@ -155,8 +155,8 @@ def view_bank(conn, bank, tree=False, users=False, parsable=False, cols=None): select_stmt = f"SELECT {', '.join(cols)} FROM bank_table WHERE bank=?" cur.execute(select_stmt, (bank,)) - # initialize AccountingFormatter object - formatter = fmt.BankFormatter(cur) + # initialize BankFormatter object + formatter = fmt.BankFormatter(cur, bank) if tree: if parsable: diff --git a/src/bindings/python/fluxacct/accounting/formatter.py b/src/bindings/python/fluxacct/accounting/formatter.py index 5d4c708b..a49ac27a 100644 --- a/src/bindings/python/fluxacct/accounting/formatter.py +++ b/src/bindings/python/fluxacct/accounting/formatter.py @@ -13,7 +13,7 @@ class AccountingFormatter: - def __init__(self, cursor): + def __init__(self, cursor, error_msg="no results found in query"): """ Initialize an AccountingFormatter object with a SQLite cursor. @@ -26,7 +26,7 @@ def __init__(self, cursor): if not self.rows: # the SQL query didn't fetch any results; raise an Exception - raise ValueError("no results found in query") + raise ValueError(error_msg) def get_column_names(self): """ @@ -102,6 +102,18 @@ class BankFormatter(AccountingFormatter): out banks/sub-banks in a hierarchical format and lists of users under banks. """ + def __init__(self, cursor, bank_name): + """ + Initialize a BankFormatter object with a SQLite cursor. + Args: + cursor: a SQLite Cursor object that has the results of a SQL query. + bank_name: the name of the bank. + """ + self.bank_name = bank_name + super().__init__( + cursor, error_msg=f"bank {self.bank_name} not found in bank_table" + ) + def as_tree(self): """ Format the flux-accounting bank hierarchy in tree format. The bank passed