Averroes / iniparse

Other
0 stars 0 forks source link

comment/uncomment options. #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Tim Lauridsen to iniparse-discuss
Aug 29

In some ini style files, like the attached fedora.repo file
some options (#baseurl=....) is commented out, if i use iniparse to add
a baseurl option, it will be added at the end of the section, because is
new option.
It would be nice if there was a way to comment/uncomment there kind of
options.

#baseurl=xxxxx -> baseurl=yyyy

baseurl=zzzz -> #baseurl=zzzz

And the order will be kept in the file.
The easiest way to implement this is to treat #baseurl=xxxx, as an
options with the name '#baseurl" and the value 'xxxx'
and the add a method to rename an option ini.rename('#baseurl','baseurl').

Tim

Original issue reported on code.google.com by psobe...@gmail.com on 25 Sep 2007 at 4:15

GoogleCodeExporter commented 9 years ago
Paramjit Oberoi to iniparse-discus
Aug 30

I can see how this can be useful in some situations...

But I'm not sure about rename() - how about comment() and uncomment()
functions instead?

Also, what if the option was specified multiple times?  Should
comment() comment out all of them?  Or only the last one?  If only the
last one is commented out, does the previous one become the active
value?

Uncomment should only uncomment one line, I think - the last one.
Should it be an error if multiple lines match?

Implementation wise, there are two choices.  One, as you suggest, is
to modify the parsing to detect all lines that are comments but could
have been valid options.  Alternatively, when comment() or uncomment()
is called, the comments could be re-parsed to identify the line to be
replaced.

Finally, what about this:

[foo]
bar=3
x=7

# [baz]
# y=9

A simple implementation of .uncomment('foo', 'y') will uncomment the
'y' in the commented out 'baz' section...

-param

Original comment by psobe...@gmail.com on 25 Sep 2007 at 4:16

GoogleCodeExporter commented 9 years ago
Tim Lauridsen to iniparse-discuss
Aug 30 

Paramjit Oberoi wrote:
 > But I'm not sure about rename() - how about comment() and uncomment()
 > functions instead?
Sounds fine

 > Also, what if the option was specified multiple times?  Should
 > comment() comment out all of them?  Or only the last one?  If only the
 > last one is commented out, does the previous one become the active
 > value?
comment() should comment all options out in the same section

 > Uncomment should only uncomment one line, I think - the last one.
 > Should it be an error if multiple lines match?
uncomment() should only the first one in a section and return the number
of remaining hit, it make it possible to
call uncomment() again until all are uncommented, if that is what the
user want.

Original comment by psobe...@gmail.com on 25 Sep 2007 at 4:18

GoogleCodeExporter commented 9 years ago
Paramjit Oberoi to iniparse-discuss
Sep 9

As I was thinking about this, I realized that although INIConfig
objects preserve comments, etc., they only provide read/write access
to values.  Maybe it's worth thinking about creating an API to access
other details of the config file?

Original comment by psobe...@gmail.com on 25 Sep 2007 at 4:19

GoogleCodeExporter commented 9 years ago
Tim Lauridsen to iniparse-discuss
Sep 9

It would be very nice if there was an API to read/write other stuff in
the config file.  Here is some ideas.
* comment/uncomment (we have discussed this one)
* Add new comments before/in option line.
* remove comment in/before option line
* rename section.

Original comment by psobe...@gmail.com on 25 Sep 2007 at 4:20