pixelb / crudini

A utility for manipulating ini files
GNU General Public License v2.0
443 stars 60 forks source link

section keys not displayed when values overlap with global defaults #50

Open makesse opened 6 years ago

makesse commented 6 years ago

I am trying to manipulate my Ansible hosts.ini files, which looks like this:

host1.example.com
host2.example.com
host3.example.com
host4.example.com

[group1]
host1.example.com
host2.example.com

[group2]
host3.example.com
host4.example.com

When I want to get all hosts (global items), I run the following command:

$ crudini --get hosts.ini ''
host1.example.com
host2.example.com
host3.example.com
host4.example.com

However, when I want to display the hosts in section group1, I do not get any output at all:

$ crudini --get hosts.ini 'group1'
$

If I modify the ini file to look like this:

host1.example.com
host2.example.com
host3.example.com
host4.example.com

[group1]
host1.example.com=1
host2.example.com=1

[group2]
host3.example.com=1
host4.example.com=1

and run the same command again I get the following output:

$ crudini --get hosts.ini 'group1'
host1.example.com
host2.example.com

Is it possible to get identical behavior for the default and the other sections?

I am running crudini-0.9-1.el7.noarch

pixelb commented 6 years ago

Indeed that's a bug that should have been handled when implementing issue #38 Thanks for the clear reproducer. It should be easy enough to address

pixelb commented 6 years ago

What's going on here is that in ini files, keys in the global section are returned as keys in each section. Therefore we have logic to strip keys from each section that overlap with the global section. To handle this case we'll have to tag the global values differently. I.e. append '.default' to the value, and only exclude those from each section.

makesse commented 6 years ago

@pixelb : thank you for the update. Is there anything I can do to help fixing this? I am not a python coder but willing to test.