Changeset - 741e6628943d
[Not reviewed]
0 3 0
Brett Smith - 3 years ago 2021-03-09 20:48:30
brettcsmith@brettcsmith.org
query: Add original query as a comment to ODS output.

This is generally helpful to keep for future reference, plus this
presentation can support multiple queries and is more discoverable than the
previous file property.
3 files changed with 38 insertions and 4 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -25,2 +25,3 @@ import git  # type:ignore[import]
 
import odf.config  # type:ignore[import]
 
import odf.dc  # type:ignore[import]
 
import odf.element  # type:ignore[import]
...
 
@@ -28,2 +29,3 @@ import odf.meta  # type:ignore[import]
 
import odf.number  # type:ignore[import]
 
import odf.office  # type:ignore[import]
 
import odf.opendocument  # type:ignore[import]
...
 
@@ -1337,2 +1339,18 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
 

	
 
    def add_annotation(
 
            self,
 
            text: Optional[str]=None,
 
            when: Optional[datetime.datetime]=None,
 
            parent: Optional[odf.table.TableCell]=None,
 
    ) -> odf.office.Annotation:
 
        if when is None:
 
            when = datetime.datetime.now()
 
        retval = odf.office.Annotation()
 
        retval.appendChild(odf.dc.Date(text=when.isoformat(timespec='seconds')))
 
        if text is not None:
 
            retval.appendChild(odf.text.P(text=text))
 
        if parent is not None:
 
            parent.appendChild(retval)
 
        return retval
 

	
 
    def add_row(self, *cells: odf.table.TableCell, **attrs: Any) -> odf.table.TableRow:
conservancy_beancount/reports/query.py
Show inline comments
...
 
@@ -215,2 +215,11 @@ class BQLShell(bc_query_shell.BQLShell):
 
        self.ods = QueryODS(rt_wrapper)
 
        self.last_line_parsed = ''
 

	
 
    def run_parser(
 
            self,
 
            line: str,
 
            default_close_date: Optional[datetime.datetime]=None,
 
    ) -> None:
 
        self.last_line_parsed = line
 
        super().run_parser(line, default_close_date)
 

	
...
 
@@ -267,3 +276,3 @@ class BQLShell(bc_query_shell.BQLShell):
 
    def _render_ods(self, statement: QueryStatement, row_types: RowTypes, rows: Rows) -> None:
 
        self.ods.write_query(statement, row_types, rows)
 
        self.ods.write_query(statement, row_types, rows, self.last_line_parsed)
 
        logger.info(
...
 
@@ -402,3 +411,9 @@ class QueryODS(core.BaseODS[NamedTuple, None]):
 

	
 
    def write_query(self, statement: QueryStatement, row_types: RowTypes, rows: Rows) -> None:
 
    def write_query(
 
            self,
 
            statement: QueryStatement,
 
            row_types: RowTypes,
 
            rows: Rows,
 
            query_string: Optional[str]=None,
 
    ) -> None:
 
        if self.is_empty():
...
 
@@ -421,2 +436,4 @@ class QueryODS(core.BaseODS[NamedTuple, None]):
 
        self.lock_first_row()
 
        if query_string:
 
            self.add_annotation(query_string, parent=self.sheet.lastChild.firstChild)
 
        cell_funcs = list(self._cell_types(statement, row_types))
...
 
@@ -578,3 +595,2 @@ def main(arglist: Optional[Sequence[str]]=None,
 
        shell.ods.set_common_properties(config.books_repo())
 
        shell.ods.set_custom_property('BeanQuery', query or '<interactive>')
 
        if args.output_file is None:
setup.py
Show inline comments
...
 
@@ -7,3 +7,3 @@ setup(
 
    description="Plugin, library, and reports for reading Conservancy's books",
 
    version='1.18.4',
 
    version='1.19.0',
 
    author='Software Freedom Conservancy',
0 comments (0 inline, 0 general)