diff options
author | Karel Klic <kklic@redhat.com> | 2011-03-01 11:32:49 +0100 |
---|---|---|
committer | Karel Klic <kklic@redhat.com> | 2011-03-01 11:32:49 +0100 |
commit | fb52104af74bbf6eeda394880666df40b4354aba (patch) | |
tree | 52b3318f050284cbac8ec96cac1701a1bf28f921 /src/retrace/abrt-retrace-cleanup.py | |
parent | 5e89938bd01a92dd2166f78e5a3541c185bae10f (diff) | |
download | abrt-fb52104af74bbf6eeda394880666df40b4354aba.tar.gz abrt-fb52104af74bbf6eeda394880666df40b4354aba.tar.xz abrt-fb52104af74bbf6eeda394880666df40b4354aba.zip |
moved retrace server code to src/retrace
Diffstat (limited to 'src/retrace/abrt-retrace-cleanup.py')
-rwxr-xr-x | src/retrace/abrt-retrace-cleanup.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/retrace/abrt-retrace-cleanup.py b/src/retrace/abrt-retrace-cleanup.py new file mode 100755 index 00000000..9286889f --- /dev/null +++ b/src/retrace/abrt-retrace-cleanup.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import os +import shutil +import sys +import time +from retrace import * + +if __name__ == "__main__": + now = int(time.time()) + + logfile = "%s/cleanup.log" % CONFIG["LogDir"] + + try: + log = open(logfile, "a") + log.write(time.strftime("[%Y-%m-%d %H:%M:%S] Running cleanup\n")) + + files = os.listdir(CONFIG["WorkDir"]) + except IOError, ex: + print "Error opening log file: %s" % ex + sys.exit(1) + except OSError, ex: + log.write("Unable to list work directory: %s" % ex) + sys.exit(2) + + for filename in files: + filepath = "%s/%s" % (CONFIG["WorkDir"], filename) + if os.path.isdir(filepath): + try: + if (now - os.path.getctime(filepath)) / 3600 >= CONFIG["DeleteTaskAfter"]: + log.write("Deleting directory '%s'\n" % filepath) + shutil.rmtree(filepath) + except OSError, ex: + log.write("Error deleting directory: %s\n" % (filepath, ex)) + except IOError, ex: + print "Unable to write to log file: %s" % ex + sys.exit(3) + + try: + log.close() + except IOError, ex: + print "Error closing log file: %s" % ex + sys.exit(4) |