cas | 2 +-
casd | 22 ----------------------
lib/cas/utilities.py | 51 ++++++++++++++++++++++++++++++++++++++++++---------
version | 2 +-
4 files changed, 44 insertions(+), 33 deletions(-)
New commits:
commit a18549114b8707f8ec684531f4560c08b3b32cd6
Author: Adam Stokes <adam(a)conans.battleaxe>
Date: Tue Nov 25 22:06:55 2008 -0500
Added another helper method to core extraction to hopefully better detect compression types.
diff --git a/cas b/cas
index 1590628..abbb67b 100755
--- a/cas
+++ b/cas
@@ -41,7 +41,7 @@ class CoreHandler(object):
return os.path.realpath(corepath)
else:
dprint("Unable to determine corefile", DPRINT)
- raise sys.exit(1)
+ sys.exit(1)
class TimestampHandler(object):
def __init__(self, corefile):
diff --git a/casd b/casd
deleted file mode 100755
index 5f3c83b..0000000
--- a/casd
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/python
-from paste import httpserver
-import simplejson
-
-def casd_app(environ, start_response):
- """
- App that shows environment
- """
- start_response('200 OK', [('Content-type', 'text/html')])
- sorted_keys = environ.keys()
- sorted_keys.sort()
- content = ['<html><body><h1>Trivial WSGI app in action</h1>'] + \
- ['<p>Sample WSGI application. Just show your environment.</p><p><ul>'] + \
- ['<li> %s : %s</li>' % (str(k), str(environ[k])) for k in sorted_keys] + \
- ['</ul></p></body></html>']
- if environ["PATH_INFO"] == "/test":
- myDict = {"full_name":"adam stokes","ownership":"administrator"}
- return simplejson.dumps(myDict)
- return content
-
-httpserver.serve(casd_app, host="127.0.0.1", port=8080)
-
diff --git a/lib/cas/utilities.py b/lib/cas/utilities.py
index 937d8c9..d25aae8 100755
--- a/lib/cas/utilities.py
+++ b/lib/cas/utilities.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
import cPickle
import commands
@@ -11,7 +11,7 @@ import logging
import urlparse
import urlgrabber.grabber as grabber
-from subprocess import Popen, PIPE
+from subprocess import Popen, PIPE, call
# setup logging
logging.basicConfig(level=logging.DEBUG,
@@ -201,20 +201,53 @@ class CoreException(Exception):
class CoreTool(object):
def __init__(self):
self.util = Utilities()
+
+ def guess_format(self, data, fname):
+ "Return a good default Operation, judging by the first 300 bytes or so."
+ suffix_map = { "tar" : ["tar", "xvf"],
+ "tgz" : ["tar", "xvzf"],
+ "gz" : ["gunzip", "-q"],
+ "tbz" : ["tar", "xvjf"],
+ "bz2" : ["bunzip2", "-q"],
+ "Z" : ["uncompress"],
+ "zip" : ["unzip", "-f"]}
+ def string(offset, match):
+ return data[offset:offset + len(match)] == match
+
+ # Archives
+ if string(257, 'ustar\0') or string(257, 'ustar\040\040\0'):
+ return suffix_map["tar"]
+ if string(0, 'PK\003\004'): return suffix_map["zip"]
+ if string(0, 'PK00'): return suffix_map["zip"]
+
+ # Compressed streams
+ if string(0, '\037\213'):
+ if fname.endswith('.tar.gz') or fname.endswith('.tgz'):
+ return suffix_map["tgz"]
+ return suffix_map["gz"]
+ if string(0, 'BZh') or string(0, 'BZ'):
+ if fname.endswith('.tar.bz') or fname.endswith('.tar.bz2') or \
+ fname.endswith('.tbz') or fname.endswith('.tbz2'):
+ return suffix_map["tbz"]
+ return suffix_map["bz2"]
+ return False
def extractCore(self, filepath, dst):
""" utility to extract tarfile and pull out core
"""
self.dst = dst
self.filepath = filepath
- if not tarfile.is_tarfile(self.filepath):
- raise CoreException("%s : is not a properly compressed tarfile." % (self.filepath,))
+ fd = open(self.filepath, 'rb')
+ data = os.read(fd.fileno(), 1000)
+ format = self.guess_format(data, self.filepath)
+ if not format:
+ raise CoreException("Can not determine compression format.")
else:
- tar = tarfile.open(self.filepath, "r")
- # python 2.4 doesn't have extractall method
- for tarinfo in tar:
- tar.extract(tarfinfo.name, self.dst)
- #tar.extractall(self.dst)
+ os.chdir(self.dst)
+ format.append(os.path.basename(self.filepath))
+ ret = call(format)
+ if ret:
+ raise CoreException("Unable to extract file based on compression format.")
for root, dirs, files in self.util.directoryList(self.dst):
for file in files:
if self.isCorefile(file):
diff --git a/version b/version
index dd9b839..dab81ac 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-0.13 71
+0.13 74