See the answer above about bicop.
Aside, the Python package index at http://pypi.python.org/pypi is a great place to search for Python packages.
EDIT . It may be useful below if someone is trying to figure out a simple parsing, but bicop seems to be an existing solution.
If someone changed the configuration manually, and you do not want to overwrite it, does this mean that you want to insert / remove lines from the existing configuration, leaving all comments, etc. intact? This prevents parsing and then re-displays the configuration, but itβs also positive - you donβt need to parse the file completely to achieve your goal.
To add an entry, you can try a simple approach like
# define zone_you_care_about and line_you_wish_to_insert first, then: for line in bindfile.read(): out.write(line + '\n') if ('zone "%s" in' % zone_you_care_about) in line: out.write(line_you_wish_to_insert)
Similar code works to delete a line:
# define zone_you_care_about and relevant_text_to_remove, then: for line in bindfile.read(): if not relevant_text_to_remove in line: out.write(line + '\n')
You can get as much as you need with simple code snippets like this.
Michael gundlach
source share