Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59514 > unrolled thread

Best approach to edit linux configuration file

Started byHimanshu Garg <hgarg.india@gmail.com>
First post2013-11-15 05:05 -0800
Last post2013-11-16 00:16 +1100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Best approach to edit linux configuration file Himanshu Garg <hgarg.india@gmail.com> - 2013-11-15 05:05 -0800
    Re: Best approach to edit linux configuration file Chris Angelico <rosuav@gmail.com> - 2013-11-16 00:16 +1100

#59514 — Best approach to edit linux configuration file

FromHimanshu Garg <hgarg.india@gmail.com>
Date2013-11-15 05:05 -0800
SubjectBest approach to edit linux configuration file
Message-ID<f0fa9248-4435-4df9-90a8-143a4ac47d3a@googlegroups.com>
I have to setup the DNS server.  For this I have to edit the configuration files.

For this I have to search if the lines(block of text) already exist in the file and if not, I have to add them to the file.

So, I want to know what is the best way to accomplish this.

[toc] | [next] | [standalone]


#59515

FromChris Angelico <rosuav@gmail.com>
Date2013-11-16 00:16 +1100
Message-ID<mailman.2649.1384521369.18130.python-list@python.org>
In reply to#59514
On Sat, Nov 16, 2013 at 12:05 AM, Himanshu Garg <hgarg.india@gmail.com> wrote:
> I have to setup the DNS server.  For this I have to edit the configuration files.
>
> For this I have to search if the lines(block of text) already exist in the file and if not, I have to add them to the file.
>
> So, I want to know what is the best way to accomplish this.

Is your script allowed to take complete control of the file, or do you
have to cope with human edits?

If you CAN take control, things are easy. Just keep track of your own
content and match exact lines; as long as you always make consistent
output, you can look for those lines precisely.

But if, as I suspect from your (scanty) description, you can't, then
you'll need to figure out how to identify whether the lines exist or
not. That means text parsing rules. Python can definitely do this;
it's simply a matter of figuring out what you're looking for, what
you're adding, etc.

Configuring DNS is pretty easy for a script to do. I've done it
several times (though only once in Python - other languages other
times).

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web