mirror of
https://github.com/StevenBlack/hosts.git
synced 2024-07-07 13:02:27 +02:00
Issue #733: fix – more robust if the .example files are missing.
This commit is contained in:
parent
429cc64f29
commit
ed6f65d970
@ -643,6 +643,7 @@ def create_initial_file():
|
|||||||
|
|
||||||
maybe_copy_example_file(settings["blacklistfile"])
|
maybe_copy_example_file(settings["blacklistfile"])
|
||||||
|
|
||||||
|
if os.path.isfile(settings["blacklistfile"]):
|
||||||
with open(settings["blacklistfile"], "r") as curFile:
|
with open(settings["blacklistfile"], "r") as curFile:
|
||||||
write_data(merge_file, curFile.read())
|
write_data(merge_file, curFile.read())
|
||||||
|
|
||||||
@ -742,6 +743,7 @@ def remove_dups_and_excl(merge_file, exclusion_regexes, output_file=None):
|
|||||||
number_of_rules = settings["numberofrules"]
|
number_of_rules = settings["numberofrules"]
|
||||||
maybe_copy_example_file(settings["whitelistfile"])
|
maybe_copy_example_file(settings["whitelistfile"])
|
||||||
|
|
||||||
|
if os.path.isfile(settings["whitelistfile"]):
|
||||||
with open(settings["whitelistfile"], "r") as ins:
|
with open(settings["whitelistfile"], "r") as ins:
|
||||||
for line in ins:
|
for line in ins:
|
||||||
line = line.strip(" \t\n\r")
|
line = line.strip(" \t\n\r")
|
||||||
@ -960,6 +962,7 @@ def write_opening_header(final_file, **header_params):
|
|||||||
preamble = path_join_robust(BASEDIR_PATH, "myhosts")
|
preamble = path_join_robust(BASEDIR_PATH, "myhosts")
|
||||||
maybe_copy_example_file(preamble)
|
maybe_copy_example_file(preamble)
|
||||||
|
|
||||||
|
if os.path.isfile(preamble):
|
||||||
with open(preamble, "r") as f:
|
with open(preamble, "r") as f:
|
||||||
write_data(final_file, f.read())
|
write_data(final_file, f.read())
|
||||||
|
|
||||||
@ -1221,6 +1224,8 @@ def maybe_copy_example_file(file_path):
|
|||||||
|
|
||||||
If the path does exist, nothing happens in this function.
|
If the path does exist, nothing happens in this function.
|
||||||
|
|
||||||
|
If the path doesn't exist, and the ".example" file doesn't exist, nothing happens in this function.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
file_path : str
|
file_path : str
|
||||||
@ -1229,6 +1234,7 @@ def maybe_copy_example_file(file_path):
|
|||||||
|
|
||||||
if not os.path.isfile(file_path):
|
if not os.path.isfile(file_path):
|
||||||
example_file_path = file_path + ".example"
|
example_file_path = file_path + ".example"
|
||||||
|
if os.path.isfile(example_file_path):
|
||||||
shutil.copyfile(example_file_path, file_path)
|
shutil.copyfile(example_file_path, file_path)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user