summaryrefslogtreecommitdiffstats
path: root/customgrabber.py
diff options
context:
space:
mode:
authorIzhar Firdaus <kagesenshi.87@gmail.com>2008-12-25 14:03:30 +0800
committerIzhar Firdaus <kagesenshi.87@gmail.com>2008-12-25 14:03:30 +0800
commitb21bdb45133d109ff1b73b524ff3f0a29a3eaefe (patch)
tree6c9e232639dde3e9ffa045e01e395c0a2a1d49cc /customgrabber.py
downloadhack-patches-b21bdb45133d109ff1b73b524ff3f0a29a3eaefe.tar.gz
hack-patches-b21bdb45133d109ff1b73b524ff3f0a29a3eaefe.tar.xz
hack-patches-b21bdb45133d109ff1b73b524ff3f0a29a3eaefe.zip
- added fastestmirror patch
- added AxelGrabber URLGrabber
Diffstat (limited to 'customgrabber.py')
-rw-r--r--customgrabber.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/customgrabber.py b/customgrabber.py
new file mode 100644
index 0000000..04647bf
--- /dev/null
+++ b/customgrabber.py
@@ -0,0 +1,52 @@
+# file: /usr/lib/python2.5/site-packages/urlgrabber/customgrabber.py
+
+import grabber, sys, os
+import subprocess
+import urllib2
+
+def get_filesize(url):
+ usock = urllib2.urlopen(url)
+ size = usock.info().get('Content-Length')
+ if size is None:
+ size = 0
+ return float(size)
+
+class AxelGrabber(grabber.URLGrabber):
+ def urlgrab(self, url, filename=None, **kwargs):
+ """grab the file at and make a local copy at
+ If filename is none, the basename of the url is used.
+ urlgrab returns the filename of the local file, which may be
+ different from the passed-in filename if copy_local == 0.
+ """
+
+ opts = self.opts.derive(**kwargs)
+ (url,parts) = opts.urlparser.parse(url, opts)
+ (scheme, host, path, parm, query, frag) = parts
+
+
+ def retryfunc(opts, url, filename):
+ fsize = get_filesize(url)
+ if (fsize/1024) < 100:
+ parts = 1
+ elif (fsize/1024) < 500:
+ parts = 2
+ elif (fsize/1024/1024) < 1:
+ parts = 3
+ elif (fsize/1024/1024) < 5:
+ parts = 4
+ elif (fsize/1024/1024) < 10:
+ parts = 6
+ elif (fsize/1024/1024) < 15:
+ parts = 8
+ else:
+ parts = 10
+ if os.path.exists(filename):
+ if not os.path.exists("%s.st" % filename):
+ os.unlink(filename)
+ p = subprocess.Popen(['/usr/bin/axel','-n','%s' % parts,'-a','-o',filename,url],stdout=sys.stdout,stderr=sys.stderr)
+ o = p.wait()
+ if o:
+ raise grabber.URLGrabError(-1)
+ return filename
+
+ return self._retry(opts, retryfunc, url, filename)