All pastes #802235 Raw Edit

Omer F. USTA

public diff v1 · immutable
#802235 ·published 2007-11-30 00:27 UTC
rendered paste body
--- fetcher.py.old	Fri Nov 30 00:47:35 2007+++ fetcher.py	Fri Nov 30 02:25:23 2007@@ -99,13 +99,13 @@ class UIHandler: class Fetcher:     """Fetcher can fetch a file from various sources using various     protocols."""-    def __init__(self, url, destdir):+    def __init__(self, url, destdir,wait=False):         if not isinstance(url, pisi.uri.URI):             url = pisi.uri.URI(url)          if ctx.config.get_option("authinfo"):             url.set_auth_info(ctx.config.get_option("authinfo"))-+        self.waitUntilConnection = wait         self.url      = url         self.destdir  = destdir         self.archive_file = os.path.join(self.destdir, self.url.filename())@@ -144,7 +144,15 @@ class Fetcher:                            reget        = self._test_range_support(),                            user_agent   = 'PiSi Fetcher/' + pisi.__version__)         except urlgrabber.grabber.URLGrabError, e:-            raise FetchError(_('Could not fetch destination file "%s": %s') % (self.archive_file, e))+            if self.checkInternetConnection():+                raise FetchError(_('Could not fetch destination file "%s": %s') % (self.archive_file, e))+            else:+                if self.waitUntilConnection:+                    print "D: 5 sn sonra tekrar denenecek"+                    time.sleep(5)+                    self.fetch()+                else:+                    raise FetchError(_('Check whether got a stable internet connection or not'))          if os.stat(self.partial_file).st_size == 0:             os.remove(self.partial_file)@@ -192,6 +200,15 @@ class Fetcher:             return 1024 * int(bandwidth_limit)         else:             return 0+        +    def checkInternetConnection(self):+        import urllib2+        try:+            file_obj = urllib2.urlopen("http://www.pardus.org.tr/resim/tubitak-uekae.png")+            file_obj.close()+            return True+        except:+            return False      def _test_range_support(self):         if not os.path.exists(self.partial_file):@@ -210,7 +227,10 @@ class Fetcher:   # helper function-def fetch_url(url, destdir, progress=None):-    fetch = Fetcher(url, destdir)-    fetch.progress = progress-    fetch.fetch()+def fetch_url(url, destdir, progress=None,wait=False):+    fetch = Fetcher(url, destdir,wait)+    if fetch.checkInternetConnection():+        fetch.progress = progress+        fetch.fetch()+    else:+        raise FetchError(_('Check whether got a stable internet connection or not'))