maybe_copy_example_file(settings["blacklistfile"])
- with open(settings["blacklistfile"], "r") as curFile:
- write_data(merge_file, curFile.read())
+ if os.path.isfile(settings["blacklistfile"]):
+ with open(settings["blacklistfile"], "r") as curFile:
+ write_data(merge_file, curFile.read())
return merge_file
number_of_rules = settings["numberofrules"]
maybe_copy_example_file(settings["whitelistfile"])
- with open(settings["whitelistfile"], "r") as ins:
- for line in ins:
- line = line.strip(" \t\n\r")
- if line and not line.startswith("#"):
- settings["exclusions"].append(line)
+ if os.path.isfile(settings["whitelistfile"]):
+ with open(settings["whitelistfile"], "r") as ins:
+ for line in ins:
+ line = line.strip(" \t\n\r")
+ if line and not line.startswith("#"):
+ settings["exclusions"].append(line)
if not os.path.exists(settings["outputpath"]):
os.makedirs(settings["outputpath"])
preamble = path_join_robust(BASEDIR_PATH, "myhosts")
maybe_copy_example_file(preamble)
- with open(preamble, "r") as f:
- write_data(final_file, f.read())
+ if os.path.isfile(preamble):
+ with open(preamble, "r") as f:
+ write_data(final_file, f.read())
final_file.write(file_contents)
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
if not os.path.isfile(file_path):
example_file_path = file_path + ".example"
- shutil.copyfile(example_file_path, file_path)
+ if os.path.isfile(example_file_path):
+ shutil.copyfile(example_file_path, file_path)
def get_file_by_url(url):