From c90390d255fef70e98a823b07163ae8631f41cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Mon, 6 Feb 2017 15:43:04 +0100 Subject: [PATCH] replaced tempfile.TemporaryDirectory with own (backwards compatibility) --- coub-dl.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index ea7bb28..cf016e6 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -7,7 +7,8 @@ from datetime import timedelta from math import floor from argparse import ArgumentParser from functools import wraps -from tempfile import TemporaryDirectory +from tempfile import mkdtemp +from shutil import rmtree @@ -181,6 +182,16 @@ def yes_no_question(question, default): print("Please respond with 'yes'(y) or 'no'(n)!") +# tempfile.TemporaryDirectory replacement to provide backwards compatibility +class temporary_directory: + def __enter__(self): + self.name = mkdtemp() + return self.name + + def __exit__(self, exc_type, exc_val, exc_tb): + rmtree(self.name) + + if __name__ == '__main__': args = parse_cmd_arguments() @@ -206,7 +217,7 @@ if __name__ == '__main__': remove(FILES[File.OUTPUT]) # create temporary directory to work in - with TemporaryDirectory() as dir: + with temporary_directory() as dir: # update temporary file locations in FILES dict for key in {key: FILES[key] for key in FILES if key not in OUTPUT_KEYS}: FILES[key] = join(dir, FILES[key])