On Fri, Jun 29, 2012 at 09:28:55AM -0400, Chris Lumens wrote:
+class EditConfig(object):
- """
- Edit values in a configuration file without changing comments.
- Supports KEY=VALUE lines and ignores everything else.
- Does not allow adding or deleting keys.
- Does not support duplicate key entries.
- ec = EditConfig("/path/to/file")
- ec.values is a dict of keys from the file, edit as needed then call:
- ec.write()
- """
Is python's ConfigParser insufficient for this purpose?
ConfigParser operates on .ini style config files, not shell style. In this case we just want to change an option in a shell-like config file without disrupting the rest of it. wwoods also suggested that the shlex module might be useful, but I think that's overkill for what we need.