D'oh!

Fixed.

Honza

Dne 15.2.2011 18:14, Rob Crittenden napsal(a):
Jan Cholasta wrote:
Fixes handling of empty lines, erroneous lines and comments in
/etc/hosts.

https://fedorahosted.org/freeipa/ticket/971


nack.

Would using line.rstrip() be better than the conditional checking
explicitly for \n?

I don't think we can use format this way, isn't it new to python 2.7? I
think you have to use {0} and {1}. We need to support python 2.6 as well.

rob

>From 786079981d60c341de821ab9061eefa6b36333e4 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jchol...@redhat.com>
Date: Tue, 15 Feb 2011 17:51:18 +0100
Subject: [PATCH] Fix handling of /etc/hosts

ticket 971
---
 ipaserver/install/installutils.py |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 563333b..21c0d78 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -159,13 +159,22 @@ def verify_ip_address(ip):
 def record_in_hosts(ip, host_name, file="/etc/hosts"):
     hosts = open(file, 'r').readlines()
     for line in hosts:
-        hosts_ip = line.split()[0]
-        if hosts_ip != ip:
+        line = line.rstrip('\n')
+        fields = line.partition('#')[0].split()
+        if len(fields) == 0:
             continue
 
-        names = line.split()[1:]
-        if host_name in names:
-            return True
+        try:
+            hosts_ip = fields[0]
+            names = fields[1:]
+
+            if hosts_ip != ip:
+                continue
+            if host_name in names:
+                return True
+        except IndexError:
+            print "Warning: Erroneous line '%s' in %s" % (line, file)
+            continue            
 
     return False
 
-- 
1.7.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to