replaced tempfile.TemporaryDirectory with own (backwards compatibility)
This commit is contained in:
parent
8d19a00cf5
commit
c90390d255
15
coub-dl.py
15
coub-dl.py
@ -7,7 +7,8 @@ from datetime import timedelta
|
|||||||
from math import floor
|
from math import floor
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from functools import wraps
|
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)!")
|
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__':
|
if __name__ == '__main__':
|
||||||
args = parse_cmd_arguments()
|
args = parse_cmd_arguments()
|
||||||
@ -206,7 +217,7 @@ if __name__ == '__main__':
|
|||||||
remove(FILES[File.OUTPUT])
|
remove(FILES[File.OUTPUT])
|
||||||
|
|
||||||
# create temporary directory to work in
|
# create temporary directory to work in
|
||||||
with TemporaryDirectory() as dir:
|
with temporary_directory() as dir:
|
||||||
# update temporary file locations in FILES dict
|
# update temporary file locations in FILES dict
|
||||||
for key in {key: FILES[key] for key in FILES if key not in OUTPUT_KEYS}:
|
for key in {key: FILES[key] for key in FILES if key not in OUTPUT_KEYS}:
|
||||||
FILES[key] = join(dir, FILES[key])
|
FILES[key] = join(dir, FILES[key])
|
||||||
|
Loading…
Reference in New Issue
Block a user