Go to file
Karl MacMillan cfaa18a1cf On 10/4/07, Rob Crittenden <rcritten@redhat.com> wrote:
> William Jon McCann wrote:
> > Hi,
> >
> > After playing with the install (repeatedly) I ended up with a lot of
> > duplicate values in:
> > /etc/sysconfig/dirsrv
> > /etc/sysconfig/ipa-kpasswd
> >
> > Here is a patch that should fix this.  It modifies the file "in-place"
> > and removes lines that matching the key (or commented key) and then
> > appends the new key=value.
> >
> > Jon
>
> Cool, I've wanted to fix this for a while (and recently aborted a switch
> from open with "a" to "w").
>
> What happens if the file doesn't exist yet? Do we need to wrap the
> fileinput loop in either a try/except or just look to see if the file
> exists first (my vote)?
>
> Something like:
>
> def update_key_val_in_file(filename, key, val):
>      if os.path.exists(filename):
>          pattern = "^[\s#]*%s\s*=" % re.escape(key)
>          p = re.compile(pattern)
>          for line in fileinput.input(filename, inplace=1):
>              if not p.search(line):
>                  sys.stdout.write(line)
>          fileinput.close()
>      f = open(filename, "a")
>      f.write("%s=%s\n" % (key, val))
>      f.close()

Good point.  In genera,l I prefer doing a try because it is a little
less racy but in this case it doesn't make a difference.

Updated patch attached.

Thanks,
Jon
0001-01-01 00:00:00 +00:00
ipa-admintools Do group operations based on the group DN, not the CN 2007-10-02 16:56:51 -04:00
ipa-client Do per-user browser configuration 2007-09-24 17:29:51 -04:00
ipa-python Fixes none values in first/last name to display properly. 2007-10-04 12:20:00 -07:00
ipa-server On 10/4/07, Rob Crittenden <rcritten@redhat.com> wrote: 0001-01-01 00:00:00 +00:00
.hgtags Added tag milestone_4 for changeset 8227ce764d491a942389f7a9f654f69d2701cb12 2007-10-02 12:18:33 -04:00
Makefile Misc small fixes 0001-01-01 00:00:00 +00:00