From b93b427a6e0f2edd3f8f4a2ab8a1bb80dda344c7 Mon Sep 17 00:00:00 2001 From: funilrys Date: Sat, 13 Jul 2019 13:41:36 +0200 Subject: [PATCH] fix #744 #843 and disable E203 (flake8). Indeed, before this patch, no `# Title: XYZ` was describing our generated host file. This patch fixes that. Indeed, we now do the following: - If no extension is included we add: - `# Title: StevenBlack/hosts` - If exactly one extension is included we add: - `# Title: StevenBlack/hosts with the extension_name extension` - If more than one extension is included we add (in one line): - `# Title: StevenBlack/hosts with the extname1, extname2 and extname3 extensions` Please also note that I disable E203 (whitespace before ':') for flake8 at line 773. Since we use Black for code formatting let me redirect you to the documentation of Black which explain what I did. https://black.readthedocs.io/en/stable/the_black_code_style.html#slices : > Since E203 is not PEP 8 compliant, you should tell > Flake8 to ignore these warnings. --- updateHostsFile.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index dbb244817..e554fe891 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -769,7 +769,9 @@ def compress_file(input_file, target_ip, output_file): if line.startswith(target_ip): if lines[lines_index].count(" ") < 9: - lines[lines_index] += " " + line[target_ip_len : line.find("#")].strip() + lines[lines_index] += ( + " " + line[target_ip_len : line.find("#")].strip() # noqa: E203 + ) else: lines[lines_index] += "\n" lines.append(line[: line.find("#")].strip()) @@ -1032,6 +1034,29 @@ def write_opening_header(final_file, **header_params): + "\n", ) + if len(header_params["extensions"]) > 1: + write_data( + final_file, + "# Title: StevenBlack/hosts with the {0} and {1} extensions\n".format( + ", ".join(header_params["extensions"][:-1]), + header_params["extensions"][-1], + ), + ) + else: + write_data( + final_file, + "# Title: StevenBlack/hosts with the {0} extension\n".format( + ", ".join(header_params["extensions"]) + ), + ) + else: + write_data( + final_file, + "# Title: StevenBlack/hosts\n".format( + ", ".join(header_params["extensions"]) + ), + ) + write_data( final_file, (