summaryrefslogtreecommitdiffstats
path: root/retrace/interface/retrace.py
diff options
context:
space:
mode:
authorMichal Toman <mtoman@redhat.com>2010-10-12 16:04:25 +0200
committerMichal Toman <mtoman@redhat.com>2010-10-12 16:04:25 +0200
commitbce30a209e7b823f67b4651e671faa64cc2af79c (patch)
tree7e5efb6da30da0e7872eb3ecc6f7e69ec33f3f3b /retrace/interface/retrace.py
parent354f20ef323c1670cb595feb1f3a19c260e8b7d6 (diff)
downloadabrt-bce30a209e7b823f67b4651e671faa64cc2af79c.tar.gz
abrt-bce30a209e7b823f67b4651e671faa64cc2af79c.tar.xz
abrt-bce30a209e7b823f67b4651e671faa64cc2af79c.zip
Retrace server interface
Diffstat (limited to 'retrace/interface/retrace.py')
-rw-r--r--retrace/interface/retrace.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/retrace/interface/retrace.py b/retrace/interface/retrace.py
new file mode 100644
index 00000000..87f48c53
--- /dev/null
+++ b/retrace/interface/retrace.py
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+import os
+import re
+import ConfigParser
+from webob import Request
+from subprocess import *
+
+REQUIRED_FILES = ["architecture", "coredump", "package"] #, "packages"]
+
+DF_OUTPUT_PARSER = re.compile("^([^ ^\t]*)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+%)[ \t]+(.*)$")
+XZ_OUTPUT_PARSER = re.compile("^totals[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+\.[0-9]+)[ \t]+([^ ^\t]+)[ \t]+([0-9]+)[ \t]+([0-9]+)$")
+
+CONFIG_FILE = "/etc/abrt/retrace.conf"
+CONFIG = {
+ "MaxParallelTasks": 2,
+ "MaxPackedSize": 30,
+ "MaxUnpackedSize": 600,
+ "MinStorageLeft": 10240,
+ "WorkDir": "/var/spool/abrt-retrace",
+}
+
+def read_config():
+ parser = ConfigParser.ConfigParser()
+ parser.read(CONFIG_FILE)
+ for key in CONFIG.keys():
+ vartype = type(CONFIG[key])
+ if vartype is int:
+ get = parser.getint
+ elif vartype is bool:
+ get = parser.getbool
+ elif vartype is float:
+ get = parser.getfloat
+ else:
+ get = parser.get
+
+ try:
+ CONFIG[key] = get("retrace", key)
+ except:
+ pass
+
+def free_space(path):
+ pipe = Popen(["df", path], stdout=PIPE).stdout
+ for line in pipe.readlines():
+ match = DF_OUTPUT_PARSER.match(line)
+ if match:
+ pipe.close()
+ return 1024 * int(match.group(4))
+
+ pipe.close()
+ return None
+
+def unpacked_size(archive):
+ pipe = Popen(["/usr/local/bin/xz", "--list", "--robot", archive], stdout=PIPE).stdout
+ for line in pipe.readlines():
+ match = XZ_OUTPUT_PARSER.match(line)
+ if match:
+ pipe.close()
+ return int(match.group(4))
+
+ pipe.close()
+ return None
+
+def new_crash():
+ i = 1
+ newdir = CONFIG["WorkDir"] + "/0"
+ while os.path.exists(newdir):
+ i += 1
+ newdir = CONFIG["WorkDir"] + "/" + str(i)
+
+ try:
+ os.mkdir(newdir)
+ return i, newdir
+ except:
+ return None, None
+
+def unpack(archive):
+ pipe = Popen(["tar", "xJf", archive])
+ pipe.wait()
+ return pipe.returncode
+
+def get_task_password(crashdir):
+ return "Password for " + crashdir
+
+def get_task_est_time(crashdir):
+ return 10
+
+def response(start_response, status, body="", extra_headers=[]):
+ start_response(status, [("Content-Type", "text/plain"), ("Content-Length", str(len(body)))] + extra_headers)
+ return [body]