Fixed the number of domains in each line.
authorStefano <redacted>
Tue, 2 Jan 2018 21:35:27 +0000 (22:35 +0100)
committerStefano <redacted>
Tue, 2 Jan 2018 21:35:27 +0000 (22:35 +0100)
Fixed the number of domains in each line and added the support to
inline comments (they will be ignored as the comment lines).
Code refactoring.

updateHostsFile.py

index 23b95174347e471a82f83ad57624897b5abbbdbc..76a76acd13ea5432e188c8a46a3db5cf3a2d7585 100644 (file)
@@ -671,16 +671,13 @@ def compress_file(input_file, target_ip, output_file):
     lines_index = 0
     for line in input_file.readlines():
         line = line.decode("UTF-8")
-        if line.startswith(('#', '\n')):
-            continue
 
         if line.startswith(target_ip):
-            current_len = len(lines[lines_index])
-            if current_len < 128 and (current_len + len(line[7:])) < 192:
-                lines[lines_index] += line[7:-1]
+            if lines[lines_index].count(' ') < 9:
+                lines[lines_index] += ' ' + line[7:line.find('#')].strip()
             else:
                 lines[lines_index] += '\n'
-                lines.append(line[:-1])
+                lines.append(line[:line.find('#')].strip())
                 lines_index += 1
 
     for line in lines:
git clone https://git.99rst.org/PROJECT