From: Stefano Date: Sat, 30 Dec 2017 19:55:12 +0000 (+0100) Subject: Added an option to compress the created hosts file. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=ff9e05ffecbf87450e0734f28be2086639d271b4;p=stevenblack-hosts.git Added an option to compress the created hosts file. In particular, the compression option removes non-necessary lines (empty lines and comments) and puts multiple domains in each line. This option should solve the issue #411 regarding the DNS client service of Windows. --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 3264d3e74..6ee62903a 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -648,8 +648,10 @@ def create_initial_file(): def compress_file(input_file, target_ip, output_file): """ - Reduce the file dimension removing non-necessary lines (empty lines and comments) and putting multiple domains in each line. - Reducing the number of lines of the file, the parsing under Microsoft Windows is much faster. + Reduce the file dimension removing non-necessary lines (empty lines and + comments) and putting multiple domains in each line. + Reducing the number of lines of the file, the parsing under Microsoft + Windows is much faster. Parameters ---------- @@ -672,8 +674,8 @@ def compress_file(input_file, target_ip, output_file): continue if line.startswith(target_ip): - l = len(lines[lines_index]) - if l < 128 and (l + len(line[7:])) < 192: + current_len = len(lines[lines_index]) + if current_len < 128 and (current_len + len(line[7:])) < 192: lines[lines_index] += line[7:-1] else: lines[lines_index] += '\n' @@ -700,7 +702,8 @@ def remove_dups_and_excl(merge_file, exclusion_regexes, output_file=None): exclusion_regexes : list The list of regex patterns used to exclude domains. output_file : file - The file object in which the result is written. If None, the file 'settings["outputpath"]' will be created. + The file object in which the result is written. If None, the file + 'settings["outputpath"]' will be created. """ number_of_rules = settings["numberofrules"]