Issue #733: fix – more robust if the .example files are missing.

This commit is contained in:
StevenBlack 2018-09-08 21:19:51 -04:00
parent 429cc64f29
commit ed6f65d970

View File

@ -643,6 +643,7 @@ def create_initial_file():
maybe_copy_example_file(settings["blacklistfile"])
if os.path.isfile(settings["blacklistfile"]):
with open(settings["blacklistfile"], "r") as curFile:
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"]
maybe_copy_example_file(settings["whitelistfile"])
if os.path.isfile(settings["whitelistfile"]):
with open(settings["whitelistfile"], "r") as ins:
for line in ins:
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")
maybe_copy_example_file(preamble)
if os.path.isfile(preamble):
with open(preamble, "r") as f:
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 doesn't exist, and the ".example" file doesn't exist, nothing happens in this function.
Parameters
----------
file_path : str
@ -1229,6 +1234,7 @@ def maybe_copy_example_file(file_path):
if not os.path.isfile(file_path):
example_file_path = file_path + ".example"
if os.path.isfile(example_file_path):
shutil.copyfile(example_file_path, file_path)