Issue 31 in iniparse: Add option after commented-out option example

1 view
Skip to first unread message

inip...@googlecode.com

unread,
May 27, 2013, 10:09:08 AM5/27/13
to iniparse...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 31 by sascha.peilicke: Add option after commented-out option
example
http://code.google.com/p/iniparse/issues/detail?id=31

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

Attachments:
iniparse-insert-after-commented-option.patch 3.7 KB

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

inip...@googlecode.com

unread,
May 27, 2013, 10:10:08 AM5/27/13
to iniparse...@googlegroups.com

Comment #1 on issue 31 by sascha.peilicke: Add option after commented-out
option example
http://code.google.com/p/iniparse/issues/detail?id=31

Gah, hand-crafted markup went the way of the dodo

inip...@googlecode.com

unread,
May 27, 2013, 10:16:49 AM5/27/13
to iniparse...@googlegroups.com

Comment #2 on issue 31 by sascha.peilicke: Add option after commented-out
option example
http://code.google.com/p/iniparse/issues/detail?id=31

(No comment was entered for this change.)

Attachments:
iniparse-insert-after-commented-option.patch 3.7 KB

inip...@googlecode.com

unread,
May 27, 2013, 10:17:49 AM5/27/13
to iniparse...@googlegroups.com

Comment #3 on issue 31 by sascha.peilicke: Add option after commented-out

inip...@googlecode.com

unread,
May 27, 2013, 10:20:39 AM5/27/13
to iniparse...@googlegroups.com

Comment #4 on issue 31 by sascha.peilicke: Add option after commented-out
option example
http://code.google.com/p/iniparse/issues/detail?id=31

(No comment was entered for this change.)

Attachments:
iniparse-insert-after-commented-option.patch 3.8 KB

inip...@googlecode.com

unread,
Jun 3, 2013, 11:52:43 AM6/3/13
to iniparse...@googlegroups.com
Updates:
Status: Accepted

Comment #5 on issue 31 by psobe...@gmail.com: Add option after
Hi Sascha,

Thanks for the patch!

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

inip...@googlecode.com

unread,
Jun 9, 2013, 10:03:06 AM6/9/13
to iniparse...@googlegroups.com
Updates:
Owner: psobe...@gmail.com

Comment #6 on issue 31 by psobe...@gmail.com: Add option after
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?

inip...@googlecode.com

unread,
Jun 14, 2013, 10:26:07 AM6/14/13
to iniparse...@googlegroups.com

Comment #7 on issue 31 by sascha.peilicke: Add option after commented-out
option example
http://code.google.com/p/iniparse/issues/detail?id=31

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....
Reply all
Reply to author
Forward
0 new messages