开发者

What is the easiest way in python to modify linux config file?

I have some python scripts that configure linux computers. One of the tasks is to modify a configuration file for subversion. This file, ~/.subversion/servers is very simple and looks like this:

# store-passwords = no
# store-plaintext-passwords = no
# store-ssl-client-cert-pp = no
# store-ssl-client-cert-pp-plaintext = no
... lots of other options ...

The task of my script is to find a required option, for example store-plaintext-passwords and to set it to specified value, for example yes. The prob开发者_运维百科lem is: the script can run multiple times on same machine, so if it is run first time this option can be just commented, if it is run second time it can be uncommented and set to yes, third run can point out that it is uncommented - but set to no etc. Currently i have a rather complex code that search file for the string, splits it for comment/name/value, uncomments it if needed, changes value if needed and replaces it. Maybe it's an easier way possible?


The ~/.subversion/servers file is in INI format.

So you can use the ConfigParser for implementing whatever you need.

http://docs.python.org/library/configparser.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜