From: Anthony Molinaro Date: Wed, 8 Apr 2020 03:08:23 +0000 (-0700) Subject: keep checkout clean X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=2d696a42d98212310b80f6085172bd6d67eea7ea;p=stevenblack-hosts.git keep checkout clean --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 89e70c944..15a33a0cc 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -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)