From 027f01e0369f9a38c80ff6ae3ac84c8746c11f60 Mon Sep 17 00:00:00 2001 From: Arthur Golubtsov Date: Fri, 15 Nov 2019 09:03:42 +0000 Subject: [PATCH] Client: Fix /etc/hosts modifying --- Drone/copter_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Drone/copter_client.py b/Drone/copter_client.py index 4933916..1583c53 100644 --- a/Drone/copter_client.py +++ b/Drone/copter_client.py @@ -215,9 +215,11 @@ def configure_hosts(hostname): index_start = raw_content.find("127.0.1.1", ) index_stop = raw_content.find("\n", index_start) - _ip, current_hostname = raw_content[index_start:index_stop].split() + hosts_array = raw_content[index_start:index_stop].split() + _ip = hosts_array[0] + current_hostname = hosts_array[1] if current_hostname != hostname: - content = raw_content[:index_start] + "{} {} {}".format(_ip, hostname, hostname+'.local') + raw_content[index_stop:] + content = raw_content[:index_start] + "{} {} {}.local".format(_ip, hostname, hostname) + raw_content[index_stop:] try: with open(path, 'w') as f: f.write(content)