keep checkout clean
authorAnthony Molinaro <redacted>
Wed, 8 Apr 2020 03:08:23 +0000 (20:08 -0700)
committerAnthony Molinaro <redacted>
Wed, 8 Apr 2020 03:08:23 +0000 (20:08 -0700)
updateHostsFile.py

index 89e70c94467a750fd3a32b8005d96f21bf79f26b..15a33a0ccbbcd30c69da7302980b3eb0d74cca98 100644 (file)
@@ -147,6 +147,14 @@ def main():
         action="store_true",
         help="Skip static localhost entries " "in the final hosts file.",
     )
+    parser.add_argument(
+        "--skip-readme-data-update",
+        "-d",
+        dest="skipreadmedataupdate",
+        default=False,
+        action="store_true",
+        help="Skip update of readme data",
+    )
     parser.add_argument(
         "--output",
         "-o",
@@ -248,7 +256,9 @@ def main():
     )
 
     merge_file = create_initial_file()
-    remove_old_hosts_file(settings["backup"])
+    remove_old_hosts_file(
+      path_join_robust(settings["outputpath"], "hosts"),
+      settings["backup"])
     if settings["compress"]:
         final_file = open(path_join_robust(settings["outputpath"], "hosts"), "w+b")
         compressed_file = tempfile.NamedTemporaryFile()
@@ -275,13 +285,14 @@ def main():
     )
     final_file.close()
 
-    update_readme_data(
-        settings["readmedatafilename"],
-        extensions=extensions,
-        numberofrules=number_of_rules,
-        outputsubfolder=output_subfolder,
-        sourcesdata=sources_data,
-    )
+    if not settings["skipreadmedataupdate"]:
+        update_readme_data(
+            settings["readmedatafilename"],
+            extensions=extensions,
+            numberofrules=number_of_rules,
+            outputsubfolder=output_subfolder,
+            sourcesdata=sources_data,
+        )
 
     print_success(
         "Success! The hosts file has been saved in folder "
@@ -333,6 +344,7 @@ def prompt_for_update(freshen, update_auto):
 
     if not os.path.isfile(hosts_file):
         try:
+            print("HERE HERE")
             open(hosts_file, "w+").close()
         except (IOError, OSError):
             # Starting in Python 3.3, IOError is aliased
@@ -1272,7 +1284,7 @@ def flush_dns_cache():
             print_failure("Unable to determine DNS management tool.")
 
 
-def remove_old_hosts_file(backup):
+def remove_old_hosts_file(old_file_path, backup):
     """
     Remove the old hosts file.
 
@@ -1285,15 +1297,11 @@ def remove_old_hosts_file(backup):
         Whether or not to backup the existing hosts file.
     """
 
-    old_file_path = path_join_robust(BASEDIR_PATH, "hosts")
-
     # Create if already removed, so remove won't raise an error.
     open(old_file_path, "a").close()
 
     if backup:
-        backup_file_path = path_join_robust(
-            BASEDIR_PATH, "hosts-{}".format(time.strftime("%Y-%m-%d-%H-%M-%S"))
-        )
+        backup_file_path = old_file_path + "{}".format(time.strftime("%Y-%m-%d-%H-%M-%S"))
 
         # Make a backup copy, marking the date in which the list was updated
         shutil.copy(old_file_path, backup_file_path)
git clone https://git.99rst.org/PROJECT