fix #744 #843 and disable E203 (flake8).
authorfunilrys <redacted>
Sat, 13 Jul 2019 11:41:36 +0000 (13:41 +0200)
committerfunilrys <redacted>
Sat, 13 Jul 2019 11:41:36 +0000 (13:41 +0200)
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

index dbb244817752279f5a2edecccfdd373857120694..e554fe891a3e98d85825857d01dca74a6623b18d 100644 (file)
@@ -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,
         (
git clone https://git.99rst.org/PROJECT