diff options
author | Michal Toman <mtoman@redhat.com> | 2011-03-18 15:24:19 +0100 |
---|---|---|
committer | Michal Toman <mtoman@redhat.com> | 2011-03-18 15:24:19 +0100 |
commit | 0d536bdf06d59c125426e8c5a95a942d60076e77 (patch) | |
tree | aef9c90d7375521882f242e956b49407b9143384 /src/retrace/retrace.py | |
parent | e3b980d5668347b33514158375e3970500af27b4 (diff) | |
download | abrt-0d536bdf06d59c125426e8c5a95a942d60076e77.tar.gz abrt-0d536bdf06d59c125426e8c5a95a942d60076e77.tar.xz abrt-0d536bdf06d59c125426e8c5a95a942d60076e77.zip |
retrace server: support .tar and .tar.gz archive formats
Diffstat (limited to 'src/retrace/retrace.py')
-rw-r--r-- | src/retrace/retrace.py | 32 |
1 files changed, 25 insertions, 7 deletions
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 |