diff options
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -17,6 +17,7 @@ import contextlib import datetime import os +import fcntl import shutil import sys import warnings @@ -141,6 +142,22 @@ def load_configs(config_files): log('SETUP', 'Configuration from %s:\n\n' % config_file, text) +def cleanup(tmpdir): + try: + with open(os.path.join(config['base'], 'lock'), 'w') as lockfile: + to_delete = os.listdir(tmpdir) + fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) + fcntl.flock(lockfile, fcntl.LOCK_UN) + if os.fork() == 0: + for dirname in to_delete: + if os.path.isdir(dirname): + shutil.rmtree(dirname) + log('SETUP', 'Cleanup successful for', tmpdir) + sys.exit(0) + except IOError: + log('SETUP', 'No cleanup for', tmpdir) + + @contextlib.contextmanager def chdir(dirname=None): currentdir = os.getcwd() |