diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-06-24 10:18:20 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-06-24 10:18:20 +0200 |
commit | 82203682e7b4e8926f5083b9bdfc6545697e8e59 (patch) | |
tree | 3eb8c05c529aeb372e602a4cbd5793bc03f3be11 | |
parent | 6c63b5876259d8bc7c184409d79c3ab3c2924178 (diff) | |
parent | 6cbf7e3976ea51b0375a27974b60768fb01a2c2d (diff) | |
download | qutebrowser-82203682e7b4e8926f5083b9bdfc6545697e8e59.tar.gz qutebrowser-82203682e7b4e8926f5083b9bdfc6545697e8e59.zip |
Merge remote-tracking branch 'origin/pr/5534'
-rwxr-xr-x | scripts/asciidoc2html.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py index e7e7f680b..194293a6e 100755 --- a/scripts/asciidoc2html.py +++ b/scripts/asciidoc2html.py @@ -23,7 +23,6 @@ from typing import List, Optional import re import os -import os.path import sys import subprocess import shutil @@ -32,7 +31,7 @@ import argparse import io import pathlib -sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) +sys.path.insert(0, str(pathlib.Path(__file__).parents[1])) from scripts import utils @@ -68,7 +67,7 @@ class AsciiDoc: def cleanup(self) -> None: """Clean up the temporary home directory for asciidoc.""" if self._homedir is not None and not self._failed: - shutil.rmtree(self._homedir) + shutil.rmtree(str(self._homedir)) def build(self) -> None: """Build either the website or the docs.""" @@ -98,12 +97,12 @@ class AsciiDoc: for src, dst in files: assert self._tempdir is not None # for mypy modified_src = self._tempdir / src.name - with open(modified_src, 'w', encoding='utf-8') as modified_f, \ - open(src, 'r', encoding='utf-8') as f: + with modified_src.open('w', encoding='utf-8') as moded_f, \ + src.open('r', encoding='utf-8') as f: for line in f: for orig, repl in replacements: line = line.replace(orig, repl) - modified_f.write(line) + moded_f.write(line) self.call(modified_src, dst, *asciidoc_args) def _copy_images(self) -> None: @@ -114,7 +113,7 @@ class AsciiDoc: for filename in ['cheatsheet-big.png', 'cheatsheet-small.png']: src = pathlib.Path('doc') / 'img' / filename dst = dst_path / filename - shutil.copy(src, dst) + shutil.copy(str(src), str(dst)) def _build_website_file(self, root: pathlib.Path, filename: str) -> None: """Build a single website file.""" @@ -130,11 +129,10 @@ class AsciiDoc: outfp = io.StringIO() - with open(modified_src, 'r', encoding='utf-8') as header_file: - header = header_file.read() - header += "\n\n" + header = modified_src.read_text(encoding='utf-8') + header += "\n\n" - with open(src, 'r', encoding='utf-8') as infp: + with src.open('r', encoding='utf-8') as infp: outfp.write("\n\n") hidden = False found_title = False @@ -174,8 +172,8 @@ class AsciiDoc: current_lines = outfp.getvalue() outfp.close() - with open(modified_src, 'w+', encoding='utf-8') as final_version: - final_version.write(title + "\n\n" + header + current_lines) + modified_str = title + "\n\n" + header + current_lines + modified_src.write_text(modified_str, encoding='utf-8') asciidoc_args = ['--theme=qute', '-a toc', '-a toc-placement=manual', '-a', 'source-highlighter=pygments'] |