Fix location handler issue on notificationclient

Story: 2008529
Task: 41872

Signed-off-by: Bin Yang <bin.yang@windriver.com>
Change-Id: Ie6de14c0dcec9e54e34e55cd70a29df1c2575a73
This commit is contained in:
Bin Yang 2021-02-18 11:16:43 +08:00
parent 62be16ee36
commit 1e3fa666e9

View File

@ -11,19 +11,19 @@ def update_host(hostname, ip):
with open(hostsfile) as fd:
for line in fd.readlines():
if line.strip() == '':
if line.strip() == '' or line.startswith('#'):
Lines.append(line)
else:
h_name = line.strip().split()[1]
if h_name == hostname:
lin = "{0} {1}".format(ip, hostname)
lin = "{0} {1}\n".format(ip, hostname)
Lines.append(lin)
replaced = True
else:
Lines.append(line)
if replaced == False:
Lines.append("{0} {1}".format(ip, hostname))
Lines.append("\n{0} {1}\n".format(ip, hostname))
with open(hostsfile, 'w') as fc:
fc.writelines(Lines)