Skip to content

Commit

Permalink
hosts.windows should be in DOS/CRLF format.
Browse files Browse the repository at this point in the history
  • Loading branch information
funilrys committed Apr 2, 2022
1 parent 387c30a commit c11cb61
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ultimate_hosts_blacklist/deployment_launcher/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def generate_next_file(
input_files: List[str],
template: Optional[str] = None,
endline: Optional[str] = None,
write_mode: Optional[str] = "lf"
) -> None:
"""
A general function which write into the next file.
Expand All @@ -71,6 +72,22 @@ def generate_next_file(
The last line to write.
"""

windows_lf = "\r\n"
unix_lf = "\n"

if write_mode.lower() == "lf":
line_ending = unix_lf

if template:
template = template.replace(windows_lf, unix_lf)
elif write_mode.lower() == "crlf":
line_ending = windows_lf

if template:
template = template.replace(unix_lf, windows_lf)
else:
raise ValueError("<write_mode> not supported.")

dir_helper = DirectoryHelper(directory_path)

if dir_helper.exists():
Expand All @@ -94,15 +111,15 @@ def generate_next_file(
logging.info("Started Generation of %r", destination)

with open(
destination, "a+", encoding="utf-8"
destination, "a+", encoding="utf-8", newline=line_ending
) as destination_file_stream:
if i == 0 and template and not template_written:
logging.debug("Writting template:\n%s", template)
destination_file_stream.write(template)

template_written = True

destination_file_stream.write(f"{format_to_apply.format(line)}\n")
destination_file_stream.write(f"{format_to_apply.format(line)}{line_ending}")

if destination_file_stream.tell() >= outputs.MAX_FILE_SIZE_IN_BYTES:
logging.info(
Expand Down Expand Up @@ -305,9 +322,9 @@ def windows_hosts(*args: List[str]) -> None:
args,
template=template,
endline="# END HOSTS LIST ### DO NOT EDIT THIS LINE AT ALL ###",
write_mode="crlf"
)


def readme_md(
*, domains_files: List[str], ip_files: List[str], info_files: List[str]
) -> None:
Expand Down

0 comments on commit c11cb61

Please sign in to comment.