After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 636808 - Adding capability of reading namespaces
Adding capability of reading namespaces
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Python Bindings
git-master
Other Linux
: Normal enhancement
: ---
Assigned To: Mark Jenkins
Mark Jenkins
Depends on:
Blocks:
 
 
Reported: 2010-12-08 20:29 UTC by Christoph Holtermann
Modified: 2018-06-29 22:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch adds checking of gnc_commodity_namespace in glists (712 bytes, patch)
2010-12-15 13:03 UTC, Christoph Holtermann
committed Details | Review
Changes to example Script to include added namespace functionality (4.60 KB, patch)
2010-12-15 13:58 UTC, Christoph Holtermann
none Details | Review
Changes to example Script to include added namespace functionality (4.61 KB, patch)
2010-12-16 17:17 UTC, Christoph Holtermann
committed Details | Review
support for GncCommodityNamespace, better support for GncCommodity, and example enhancements (7.12 KB, patch)
2010-12-16 22:45 UTC, Mark Jenkins
committed Details | Review

Description Christoph Holtermann 2010-12-08 20:29:22 UTC
One small thing that came across me when I was extending the example script
to read out the commodities [1] was, that I could not read out the names of the
namespaces. I guess there has to be a modification of the interface files.
comm_table.get_namespaces_list() returns a list of
<gnucash.gnucash_core_c._gnc_monetary; proxy of <Swig Object of type '_gnc_monetary *' at 0xb5155488> >
and i don't know how to handle that type.

[1] https://bugzilla.gnome.org/attachment.cgi?id=176094
Comment 1 Christoph Holtermann 2010-12-15 13:03:43 UTC
Created attachment 176459 [details] [review]
Patch adds checking of gnc_commodity_namespace in glists

In src/base-typemaps.i check for return type gnc_commodity_namespace is added so that it is returned instead of gnc_type_monetary.
Comment 2 Christoph Holtermann 2010-12-15 13:07:17 UTC
(In reply to comment #1)
> Created an attachment (id=176459) [details] [review]
> Patch adds checking of gnc_commodity_namespace in glists
> 
> In src/base-typemaps.i check for return type gnc_commodity_namespace is added
> so that it is returned instead of gnc_type_monetary.

Please have a look at this for I am a novice. For me it works but I have at least one question :

What is the difference between src/base-typemaps.i and src/optional/python-bindings/glib.i ? In the latter the same check for glist is done.
Comment 3 Christoph Holtermann 2010-12-15 13:58:15 UTC
Created attachment 176461 [details] [review]
Changes to example Script to include added namespace functionality

The script now includes the possibility to print out all namespaces.
Comment 4 Christoph Holtermann 2010-12-15 14:00:19 UTC
The script accidentally resides in optional/... instead of src/optional/...
Comment 5 Mike Evans 2010-12-15 14:32:48 UTC
(In reply to comment #4)
> The script accidentally resides in optional/... instead of src/optional/...

Oops. Now moved to correct location.
Comment 6 Mike Evans 2010-12-15 14:41:57 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Created an attachment (id=176459) [details] [review] [details] [review]
> > Patch adds checking of gnc_commodity_namespace in glists
> > 
> > In src/base-typemaps.i check for return type gnc_commodity_namespace is added
> > so that it is returned instead of gnc_type_monetary.

> 
> Please have a look at this for I am a novice. For me it works but I have at
> least one question :
> 
> What is the difference between src/base-typemaps.i and
> src/optional/python-bindings/glib.i ? In the latter the same check for glist is
> done.

Since glib.i doesn't appear in Makefile.am I am assuming(!) that it's obsolete and it's functionality has been moved to base-typemaps.i.  If someone confirms this is the case I think it should be removed to avoid further confusion.
Comment 7 Mike Evans 2010-12-15 15:20:22 UTC
Comment on attachment 176459 [details] [review]
Patch adds checking of gnc_commodity_namespace in glists

Thanks a lot for the patch.
Comment 8 Mark Jenkins 2010-12-15 22:07:14 UTC
Indeed, src/optional/python-bindings/glib.i can be removed, a search with grep reveals it not being used anywhere, most importantly in gnucash_core.i.

The history of this was that there was an effort to move all of the the python binding functionality to shared .i files instead of ones specificic to the python bindings. Some of that did manage to take place, which is why there is a guarded section for python binding stuff in src/base-typemaps.i .

Hopefully more progress on that can happen eventually, it is the right thing to do.

I'm currious as to the status of the example scripts patch (https://bugzilla.gnome.org/attachment.cgi?id=176461), I see that the patch to src/base-typemaps.i was commited, but not the script patch?

As for the commited patch to src/base-typemaps.i, Christoph asked on list what I thought of it -- looks fine to me.

I'm tempted to add a high level wrapper for GncCommodityNamespace just like GncCommodity and GncCommodityTable. If we overrode some of these functions that return lists to return lists of these wrapper types, the example scripts would become a lot cleaner.
Comment 9 Mike Evans 2010-12-16 12:44:04 UTC
(In reply to comment #8)
> Indeed, src/optional/python-bindings/glib.i can be removed, a search with grep
> reveals it not being used anywhere, most importantly in gnucash_core.i.
> 
> The history of this was that there was an effort to move all of the the python
> binding functionality to shared .i files instead of ones specificic to the
> python bindings. Some of that did manage to take place, which is why there is a
> guarded section for python binding stuff in src/base-typemaps.i .
> 
> Hopefully more progress on that can happen eventually, it is the right thing to
> do.
> 
> I'm currious as to the status of the example scripts patch
> (https://bugzilla.gnome.org/attachment.cgi?id=176461), I see that the patch to
> src/base-typemaps.i was commited, but not the script patch?

The example script should be in the correct place now. The patch lacked the leading src/... and I didn't notice, so it went missing for a while.

> 
> As for the commited patch to src/base-typemaps.i, Christoph asked on list what
> I thought of it -- looks fine to me.
> 
> I'm tempted to add a high level wrapper for GncCommodityNamespace just like
> GncCommodity and GncCommodityTable. If we overrode some of these functions that
> return lists to return lists of these wrapper types, the example scripts would
> become a lot cleaner.

I think you should let yourself be tempted.
Comment 10 Christoph Holtermann 2010-12-16 17:17:09 UTC
Created attachment 176543 [details] [review]
Changes to example Script to include added namespace functionality

This patch changes the example script to reflect the capability of reading all namespaces. It now also is at the correct position in the directory tree.
Comment 11 Christoph Holtermann 2010-12-16 17:20:58 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > The script accidentally resides in optional/... instead of src/optional/...
> 
> Oops. Now moved to correct location.

I guess you still have to delete the directory tree optional/... in svn for when I do locally and "svn update" I get it anew.
Comment 12 Mark Jenkins 2010-12-16 22:45:43 UTC
Created attachment 176564 [details] [review]
support for GncCommodityNamespace, better support for GncCommodity, and example enhancements

The other patch from this bug that enhances the example reports has to be applied first.

Apply with -p0.

Also available via
svn merge -c 738 http://svn.parit.ca/gnucash/branches/python-bindings/
or
svn diff -c 738 http://svn.parit.ca/gnucash/branches/python-bindings/

added a high level wrapper around GncCommodityNamespace and provided 
additional wrapping for GncCommodity and GncCommodityNamespace for 
functions that return individual or lists of those

updated the price db example scripts to use this new api
Comment 13 Mike Evans 2010-12-17 17:47:26 UTC
Thanks very much to Mark and Christoph for the patches.
Comment 14 Mark Jenkins 2010-12-17 20:06:53 UTC
This extra chain of empty directories which came about from earlier applied patches still needs to be removed:
optional/python-bindings/example_scripts/

i.e.
$ svn rm optional
(from top of tree in trunk)
Comment 15 Christoph Holtermann 2010-12-17 23:49:20 UTC
(In reply to comment #12)
> Created an attachment (id=176564) [details] [review]
> support for GncCommodityNamespace, better support for GncCommodity, and example
> enhancements
Thanks very much for that. It's really interesting to see how things develop and to learn from first hand.
> 
> 
> updated the price db example scripts to use this new api

I'm curious why you changed for example

a=[]
if a:

to

if len(a)==0:

is it because it's more obvious what is checked ? I came to like the short form and it does the same job.
Comment 16 Mark Jenkins 2010-12-19 23:32:06 UTC
Regarding if len(a)==0: more obvious with very little cost for being obvious, thus fits with the philosophy:

$ python
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Comment 17 Christoph Holtermann 2010-12-19 23:36:03 UTC
Cool ;-) I guess I'm still stuck with one of my favourite books : obfuscated C ;-)
Comment 18 Christoph Holtermann 2010-12-19 23:46:22 UTC
(In reply to comment #17)
> Cool ;-) I guess I'm still stuck with one of my favourite books : obfuscated C
> ;-)

Though another thing I came across the recent times was Donald Knuths literate programming.
Comment 19 John Ralls 2018-06-29 22:49:04 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=636808. Please update any external references or bookmarks.