From 0d536bdf06d59c125426e8c5a95a942d60076e77 Mon Sep 17 00:00:00 2001 From: Michal Toman Date: Fri, 18 Mar 2011 15:24:19 +0100 Subject: retrace server: support .tar and .tar.gz archive formats --- src/retrace/create.wsgi | 6 +++--- src/retrace/retrace.py | 32 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src/retrace') diff --git a/src/retrace/create.wsgi b/src/retrace/create.wsgi index 027bd1a9..914469ec 100644 --- a/src/retrace/create.wsgi +++ b/src/retrace/create.wsgi @@ -18,7 +18,7 @@ def application(environ, start_response): if request.method != "POST": return response(start_response, "405 Method Not Allowed") - if not request.content_type in ["application/x-xz", "application/x-xz-compressed-tar", "application/x-gzip", "application/x-tar"]: + if not request.content_type in HANDLE_ARCHIVE.keys(): return response(start_response, "415 Unsupported Media Type") if not request.content_length: @@ -53,7 +53,7 @@ def application(environ, start_response): except: return response(start_response, "500 Internal Server Error", "Unable to save archive") - size = unpacked_size(archive.name) + size = unpacked_size(archive.name, request.content_type) if not size: os.unlink(archive.name) return response(start_response, "500 Internal Server Error", "Unable to obtain unpacked size") @@ -73,7 +73,7 @@ def application(environ, start_response): try: os.mkdir("%s/crash/" % taskdir) os.chdir("%s/crash/" % taskdir) - unpack_retcode = unpack(archive.name) + unpack_retcode = unpack(archive.name, request.content_type) os.unlink(archive.name) if unpack_retcode != 0: diff --git a/src/retrace/retrace.py b/src/retrace/retrace.py index ddeb9ffd..eb324037 100644 --- a/src/retrace/retrace.py +++ b/src/retrace/retrace.py @@ -12,6 +12,7 @@ REQUIRED_FILES = ["coredump", "executable", "package"] DF_BIN = "/bin/df" DU_BIN = "/usr/bin/du" +GZIP_BIN = "/usr/bin/gzip" TAR_BIN = "/bin/tar" XZ_BIN = "/usr/bin/xz" @@ -19,7 +20,6 @@ TASKID_PARSER = re.compile("^.*/([0-9]+)/*$") PACKAGE_PARSER = re.compile("^(.+)-([0-9]+(\.[0-9]+)*-[0-9]+)\.([^-]+)$") DF_OUTPUT_PARSER = re.compile("^([^ ^\t]*)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([0-9]+%)[ \t]+(.*)$") DU_OUTPUT_PARSER = re.compile("^([0-9]+)") -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]+)") URL_PARSER = re.compile("^/([0-9]+)/?") RELEASE_PARSERS = { "fedora": re.compile("^Fedora[^0-9]+([0-9]+)[^\(]\(([^\)]+)\)$"), @@ -29,6 +29,23 @@ GUESS_RELEASE_PARSERS = { "fedora": re.compile("\.fc([0-9]+)"), } +HANDLE_ARCHIVE = { + "application/x-xz-compressed-tar": { + "unpack": [TAR_BIN, "xJf"], + "size": ([XZ_BIN, "--list", "--robot"], re.compile("^totals[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+([0-9]+).*")), + }, + + "application/x-gzip": { + "unpack": [TAR_BIN, "xzf"], + "size": ([GZIP_BIN, "--list"], re.compile("^[^0-9]*[0-9]+[^0-9]+([0-9]+).*$")), + }, + + "application/x-tar": { + "unpack": [TAR_BIN, "xf"], + "size": (["ls", "-l"], re.compile("^[ \t]*[^ ^\t]+[ \t]+[^ ^\t]+[ \t]+[^ ^\t]+[ \t]+[^ ^\t]+[ \t]+([0-9]+).*$")), + }, +} + TASKPASS_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" CONFIG_FILE = "/etc/abrt/retrace.conf" @@ -89,13 +106,14 @@ def dir_size(path): pipe.close() return 0 -def unpacked_size(archive): - pipe = Popen([XZ_BIN, "--list", "--robot", archive], stdout=PIPE).stdout +def unpacked_size(archive, mime): + command, parser = HANDLE_ARCHIVE[mime]["size"] + pipe = Popen(command + [archive], stdout=PIPE).stdout for line in pipe.readlines(): - match = XZ_OUTPUT_PARSER.match(line) + match = parser.match(line) if match: pipe.close() - return int(match.group(4)) + return int(match.group(1)) pipe.close() return None @@ -191,8 +209,8 @@ def new_task(): except: return None, None, None -def unpack(archive): - pipe = Popen([TAR_BIN, "xJf", archive]) +def unpack(archive, mime): + pipe = Popen(HANDLE_ARCHIVE[mime]["unpack"] + [archive]) pipe.wait() return pipe.returncode -- cgit