lib/cas/utilities.py | 43 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 3 deletions(-)
New commits:
commit a8da19b400f740cc2e66541fbd3f0bc75b4bfb5e
Author: Adam Stokes <adam(a)conans.battleaxe>
Date: Thu Oct 30 10:50:54 2008 -0400
download support added
diff --git a/lib/cas/utilities.py b/lib/cas/utilities.py
index fea79d6..074b3c5 100755
--- a/lib/cas/utilities.py
+++ b/lib/cas/utilities.py
@@ -8,6 +8,7 @@ import sys
import shutil
import tarfile
import logging
+import urlgrabber.grabber as grabber
from subprocess import Popen, PIPE
@@ -180,7 +181,7 @@ class Utilities(object):
# Build crash input file
crashInputPath = os.path.join(dst, file_in)
crashInputFH = open(crashInputPath, "w")
- crashInFH.write(crashInputCmds)
+ crashInFH.write(",".join(crashInputCmds))
crashInFH.close()
vmcorePath = os.path.join(dst, vmcore)
@@ -244,12 +245,48 @@ class CoreTool(object):
raise CoreException("Unable to retrieve timestamp from: %s" % (path,))
class Download(object):
+""" borrowed from anaconda's urlinstall method
+"""
def __init__(self, url, dst):
self.url = url
self.dst = dst
+ (scheme, netloc, path, query, fragid) = urlparse.urlsplit(self.url)
+ self.file = os.path.basename(path)
+ self.output = os.path.join(self.dst, self.file)
+
def status(self, cur_bytes, tot_bytes):
- print("Downloaded %s of %s" % (cur_bytes, tot_bytes) + "\r")
+ sys.stdout.write("Downloaded %s of %s" % (cur_bytes, tot_bytes) +
"\r")
+ sys.stdout.flush()
def get(self):
- pass
+ try:
+ url = grabber.urlopen(self.url)
+ except: grabber.URLGrabError, e:
+ raise IOError (e.errno, e.strerror)
+
+ # check size
+ try:
+ filesize = int(url.info()["Content-Length"])
+ if filesize == 0:
+ filesize = None
+ except:
+ filesize = None
+
+ #write output
+ f = open(self.output, "w+")
+
+ buf = url.read(65535)
+ tot = len(buf)
+ while len(buf) > 0:
+ if filesize is not None:
+ self.status((100*tot)/filesize, filesize)
+ else:
+ self.status(tot/1024, filesize)
+ f.write(buf)
+ buf = url.read(65535)
+ tot += len(buf)
+
+ f.close()
+ url.close()
+ return self.output
Show replies by date