Skip to content

Export qof_book_mark_session_dirty to the Python bindings. #2090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from

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 <[email protected]>
@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