jncramp / iniparse

Automatically exported from code.google.com/p/iniparse
Other
0 stars 0 forks source link

Add option after commented-out option example #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Many applications ship annotated configuration examples which include sections 
like these:

  [section]                                                                                                                             
  # Hello
  # option1 = foo                                                                                                                       

  #option2=bazz                                                                                                                         
  #option3=spam                                                                                                                         
  bumble=bee

When you edit this example with IniParse, a human would expect the following 
result:

  [section]                                                                                                                             
  # Hello
  # option1 = foo                                                                                                                       
  option1 = bar                                                                                                                         

  #option2=bazz
  option2 = bazz                                                                                                                        
  #option3=spam
  option3 = spam                                                                                                                        
  bumble=bee  

However, currently IniParse doesn't check for commented-out option lines, thus 
the output is actually:

  [section]
  # Hello
  # option1 = foo

  #option2=bazz
  #option3=spam
  bumble=bee
  option1 = bar
  option2 = bazz
  option3 = spam

The bigger the config file becomes, the more annoying this behavior is [0]. The 
attached patch tries to provide a solution. Feel free to critize the 
implementation :-)

Footnotes:
 [0] https://github.com/openstack/nova/blob/master/etc/nova/nova.conf.sample

Original issue reported on code.google.com by sascha@peilicke.de on 27 May 2013 at 2:09

GoogleCodeExporter commented 8 years ago
Gah, hand-crafted markup went the way of the dodo

Original comment by sascha@peilicke.de on 27 May 2013 at 2:09

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago

Original comment by sascha@peilicke.de on 27 May 2013 at 2:20

Attachments:

GoogleCodeExporter commented 8 years ago
Hi Sascha,

Thanks for the patch!

I'll try to take a look at it soon.

Original comment by psobe...@gmail.com on 3 Jun 2013 at 3:52

GoogleCodeExporter commented 8 years ago
Took a look at the code, and it looks good.

One problem I can think of is that continuation lines are hard to recognize in 
a comment. For example:

# Set this to the list of allowed hosts
# hosts = host1
#         host2
#         host3

It's hard to tell if "host 2 is a continuation of the option value, or a 
continuation of the comment.

Also, sometimes the comments are about blocks of options:

# Filtering options
# filtername = xxx
# filterhost = yyy

# Reporting options
# reportname = qqq
# reporthost = rrr

When a new value is added, if we added it after the end of the comment instead 
of breaking up the comment, these issues would not come up. In other words, 
we'd set the index for all option names that are seen in a group of consecutive 
comment lines to be right after the end of the group.

Which behavior do you think would be better - breaking up the comment, or 
inserting the new option after the end of the comment?

Original comment by psobe...@gmail.com on 9 Jun 2013 at 2:02

GoogleCodeExporter commented 8 years ago
Sorry for the late reply, I don't query my gmail often. The continuation line 
thing is indeed an issue, if you would have 

# Set this to the list of allowed hosts
# hosts = host1
#         host2
#         host3

I'm sure you would expect:

# Set this to the list of allowed hosts
# hosts = host1
#         host2
#         host3
hosts = host1
        ...

When it comes to the block of options, from my experience people set options 
directly in-line, i.e. seldomly sort them. So 

# Reporting options
# reportname = qqq
# reporthost = rrr

would just become

# Reporting options
# reportname = qqq
reportname = bla
# reporthost = rrr
reporthost = blub

instead of 

# Reporting options
# reportname = qqq
# reporthost = rrr
reportname = bla
reporthost = blub

The former is easier to grok when the block of options is bigger. Another 
unmentioned issue is the [DEFAULT] group. My current code doesn't get the 
sorting right there. I've got to invest some time into that too....

Original comment by sascha@peilicke.de on 14 Jun 2013 at 2:25