From 6a76e9af5dc03acb350a339567be6e4f9cf7549c Mon Sep 17 00:00:00 2001 From: Martyn Welch <martyn.welch@collabora.com> Date: Thu, 30 Jul 2020 19:17:46 +0100 Subject: [PATCH] Clean up temporary files and directories Whilst not important in CI as they will get cleaned up, having temporary files and directories left after building locally is a pain. Tweak to clean these files up. Signed-off-by: Martyn Welch <martyn.welch@collabora.com> --- scripts/hotdoc-html-2-pdf | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/hotdoc-html-2-pdf b/scripts/hotdoc-html-2-pdf index 14edd1fb8..783ff4948 100755 --- a/scripts/hotdoc-html-2-pdf +++ b/scripts/hotdoc-html-2-pdf @@ -110,7 +110,7 @@ def convert_images(elem, imgdir): img.attrib['src'] = converted -def transform(args): +def transform(args, tmpdir_path): with io.open(args.input, 'r', encoding='utf-8') as _: contents = _.read() @@ -127,8 +127,6 @@ def transform(args): if args.remote_prefix: update_local_links(body, args.remote_prefix) - inpath = os.path.dirname(args.input) - tmpdir_path = tempfile.mkdtemp(prefix=os.path.join(inpath, '')) convert_images(body, tmpdir_path) format_lntables(body) @@ -178,6 +176,7 @@ def write(args, output): status = subprocess.call(cmd) os.close(tmp_html) + os.remove(tmp_path) return status @@ -208,7 +207,15 @@ if __name__=='__main__': args.input = os.path.abspath(args.input) args.output = os.path.abspath(args.output) - output = transform(args) + inpath = os.path.dirname(args.input) + tmpdir_path = tempfile.mkdtemp(prefix=os.path.join(inpath, '')) + + output = transform(args, tmpdir_path) status = write(args, output) + files = os.listdir(tmpdir_path) + for file in files: + os.remove(tmpdir_path + "/" + file) + os.rmdir(tmpdir_path) + sys.exit(status) -- GitLab