From 2a1c376c441284314524fe2bdb3aaffdb8942966 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sat, 18 May 2019 14:19:26 -0700 Subject: [PATCH] Override newline for file writes --- lexipython/__main__.py | 6 +++--- lexipython/build.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lexipython/__main__.py b/lexipython/__main__.py index d866e79..b30991b 100644 --- a/lexipython/__main__.py +++ b/lexipython/__main__.py @@ -136,13 +136,13 @@ def command_init(name): # Edit the name field config = re.sub("Lexicon Title", "Lexicon {}".format(name), config) # Create the Lexicon's config file - with open(os.path.join(lex_path, "lexicon.cfg"), "w") as config_file: + with open(os.path.join(lex_path, "lexicon.cfg"), "w", newline='') as config_file: config_file.write(config) # Copy the CSS file - with open(os.path.join(lex_path, "lexicon.css"), "w") as css_file: + with open(os.path.join(lex_path, "lexicon.css"), "w", newline='') as css_file: css_file.write(utils.load_resource("lexicon.css")) # Create an example page - with open(os.path.join(lex_path, "src", "example-page.txt"), "w") as destfile: + with open(os.path.join(lex_path, "src", "example-page.txt"), "w", newline='') as destfile: destfile.write(utils.load_resource("example-page.txt")) # Create an empty status file open(os.path.join(lex_path, "status"), "w").close() diff --git a/lexipython/build.py b/lexipython/build.py index 45ec841..9fc2270 100644 --- a/lexipython/build.py +++ b/lexipython/build.py @@ -417,7 +417,7 @@ def build_all(path_prefix, lexicon_name): # Write the redirect page print("Writing redirect page...") - with open(pathto("index.html"), "w", encoding="utf8") as f: + with open(pathto("index.html"), "w", encoding="utf8", newline='') as f: f.write(utils.load_resource("redirect.html").format( lexicon=config["LEXICON_TITLE"], sort=config["DEFAULT_SORT"])) @@ -430,7 +430,7 @@ def build_all(path_prefix, lexicon_name): l = len(articles) for idx in range(l): article = articles[idx] - with open(pathto("article", article.title_filesafe + ".html"), "w", encoding="utf-8") as f: + with open(pathto("article", article.title_filesafe + ".html"), "w", encoding="utf-8", newline='') as f: content = article.build_default_content() article_html = page.format( title = article.title, @@ -440,29 +440,29 @@ def build_all(path_prefix, lexicon_name): # Write default pages print("Writing default pages...") - with open(pathto("contents", "index.html"), "w", encoding="utf-8") as f: + with open(pathto("contents", "index.html"), "w", encoding="utf-8", newline='') as f: f.write(build_contents_page(config, page, articles)) print(" Wrote Contents") - with open(pathto("rules", "index.html"), "w", encoding="utf-8") as f: + with open(pathto("rules", "index.html"), "w", encoding="utf-8", newline='') as f: f.write(build_rules_page(page)) print(" Wrote Rules") - with open(pathto("formatting", "index.html"), "w", encoding="utf-8") as f: + with open(pathto("formatting", "index.html"), "w", encoding="utf-8", newline='') as f: f.write(build_formatting_page(page)) print(" Wrote Formatting") - with open(pathto("session", "index.html"), "w", encoding="utf-8") as f: + with open(pathto("session", "index.html"), "w", encoding="utf-8", newline='') as f: f.write(build_session_page(page, config["SESSION_PAGE"])) print(" Wrote Session") - with open(pathto("statistics", "index.html"), "w", encoding="utf-8") as f: + with open(pathto("statistics", "index.html"), "w", encoding="utf-8", newline='') as f: f.write(build_statistics_page(config, page, articles)) print(" Wrote Statistics") # Write auxiliary pages if "PRINTABLE_FILE" in config and config["PRINTABLE_FILE"]: - with open(pathto(config["PRINTABLE_FILE"]), "w", encoding="utf-8") as f: + with open(pathto(config["PRINTABLE_FILE"]), "w", encoding="utf-8", newline='') as f: f.write(build_compiled_page(articles, config)) print(" Wrote compiled page to " + config["PRINTABLE_FILE"]) - with open(pathto("editor.html"), "w", encoding="utf-8") as f: + with open(pathto("editor.html"), "w", encoding="utf-8", newline='') as f: editor = utils.load_resource("editor.html") writtenArticles = "" phantomArticles = ""