[WIP] python: add AccountingFormatter
class, restructure list-banks
to use new class
#520
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
flux-accounting has lots of different tables that can be viewed with
view-*
andlist-*
commands, but each one has its own function that could probably be cleaned up with some common utility. Better yet, if the formatting options for all of these commands was centralized, it might make for easier changes in the future and/or customization of output by users.This PR begins to centralize the formatting for flux-accounting by adding a new
AccountingFormatter
class to the Python bindings. The class takes a SQLiteCursor
object that has the results of running a query on the flux-accounting database and offers two methods of formatting its data: data in an adjustable table or data in JSON format. Since this class just takes aCursor
object, this means it can support customization of what fields are formatted and returned (because the query itself can just be customized to not fetch every field).As an example of using this class, I've restructured the
list-banks
command. It now makes use of this class and, depending on a new optional argument that allows users to specify if they want data in JSON format, will just pass the result of executing the query instead of defining its own format within the function.I've added some basic unit tests for the
AccountingFormatter
class as well as some sharness tests to call thelist-banks
command with different customization options and returning data in each format.