summaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'app.py')
-rw-r--r--app.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/app.py b/app.py
index 88d8327..0c6baa8 100644
--- a/app.py
+++ b/app.py
@@ -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()