Skip to content

Export qof_book_mark_session_dirty to the Python bindings.#2090

Open
rotdrop wants to merge 1 commit intoGnucash:stablefrom
rotdrop:feature/python-expose-mark-session-dirty
Open

Export qof_book_mark_session_dirty to the Python bindings.#2090
rotdrop wants to merge 1 commit intoGnucash:stablefrom
rotdrop:feature/python-expose-mark-session-dirty

Conversation

@rotdrop
Copy link

@rotdrop rotdrop commented May 24, 2025

Use case: implement a command line "save-as" script. This works by using the gnucash_core_c bindings like follows but for the problem that qof_book_mark_session_dirty() is not exported, and without "dirty" the function qof_session_save(outputSession) does nothing.

...
inputSession = gnucash_core_c.qof_session_new(gnucash_core_c.qof_book_new())
gnucash_core_c.qof_session_begin(inputSession, inputURI, SessionOpenMode.SESSION_READ_ONLY)
gnucash_core_c.qof_session_load(inputSession, None)

outputSession = gnucash_core_c.qof_session_new(gnucash_core_c.qof_book_new())
gnucash_core_c.qof_session_begin(outputSession, outputURI, SessionOpenMode.SESSION_NEW_OVERWRITE)

gnucash_core_c.qof_session_swap_data(inputSession, outputSession)
gnucash_core_c.qof_book_mark_session_dirty(gnucash_core_c.qof_session_get_book(outputSession))

gnucash_core_c.qof_session_save(outputSession, None)
gnucash_core_c.qof_session_end(outputSession)

Complete script is here https://github.com/rotdrop/gnucash-python/blob/main/src/save-as.py

Use case: implement a command line "save-as" script. This works by using
the gnucash_core_c bindings like follows but for the problem that
qof_book_mark_session_dirty() is not exported, and without "dirty" the
function `qof_session_save(outputSession)` does nothing.

```
...
inputSession = gnucash_core_c.qof_session_new(gnucash_core_c.qof_book_new())
gnucash_core_c.qof_session_begin(inputSession, inputURI, SessionOpenMode.SESSION_READ_ONLY)
gnucash_core_c.qof_session_load(inputSession, None)

outputSession = gnucash_core_c.qof_session_new(gnucash_core_c.qof_book_new())
gnucash_core_c.qof_session_begin(outputSession, outputURI, SessionOpenMode.SESSION_NEW_OVERWRITE)

gnucash_core_c.qof_session_swap_data(inputSession, outputSession)
gnucash_core_c.qof_book_mark_session_dirty(gnucash_core_c.qof_session_get_book(outputSession))

gnucash_core_c.qof_session_save(outputSession, None)
gnucash_core_c.qof_session_end(outputSession)
```

Signed-off-by: Claus-Justus Heine <himself@claus-justus-heine.de>
@rotdrop
Copy link
Author

rotdrop commented May 24, 2025

There is also an older related thread by someone else on them mailing list: https://lists.gnucash.org/pipermail/gnucash-user/2018-June/077649.html

@jralls
Copy link
Member

jralls commented May 27, 2025

Please add a test or two to exercise this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants