Python 2.7 doesn't have TemporaryDirectory

(cherry picked from commit ef81730d8a)
This commit is contained in:
Robin Dunn
2019-06-21 20:36:09 -07:00
parent 6dab1307fa
commit 03ee6dcd95
2 changed files with 21 additions and 3 deletions

View File

@@ -971,3 +971,20 @@ def updateLicenseFiles(cfg):
with open('LICENSE.txt', 'w') as f:
f.write(text)
try:
from tempfile import TemporaryDirectory
except ImportError:
from tempfile import mkdtemp
class TemporaryDirectory(object):
def __init__(self, suffix='', prefix='tmp', dir=None):
self.name = mkdtemp(suffix, prefix, dir)
def __enter__(self):
return self.name
def __exit__(self, exc, value, tb):
self.cleanup()
def cleanup(self):
shutil.rmtree(self.name)