Commits

Aleš Erjavec committed 705107a

Removed the use of global 'socket.setdefaulttimeout'.

(fixes #1310).

Comments (0)

Files changed (3)

Orange/utils/__init__.py

         dst_obj = open(os.path.join(directory, basename), "wb")
     
     if progress == True:
-        from Orange.utils import ConsoleProgressBar
         progress = ConsoleProgressBar("Downloading %r." % basename)
         with finishing(progress):
             copyfileobj(stream, dst_obj, buffer=2**10, content_len=length,

Orange/utils/addons.py

 import sys
 import platform
 import subprocess
+import urllib2
+import urlparse
+import posixpath
+import site
 
 from collections import namedtuple, defaultdict
 from contextlib import closing
 
 ADDONS_ENTRY_POINT="orange.addons"
 
-socket.setdefaulttimeout(120)  # In seconds.
 
 OrangeAddOn = namedtuple('OrangeAddOn', ['name', 'available_version', 'installed_version', 'summary', 'description',
                                          'author', 'docs_url', 'keywords', 'homepage', 'package_url',
 INDEX_RE = "[^a-z0-9-']"  # RE for splitting entries in the search index
 
 AOLIST_FILE = os.path.join(Orange.utils.environ.orange_settings_dir, "addons.shelve")
+
 def open_addons():
     try:
         addons = shelve.open(AOLIST_FILE, 'c')
 def install(name, progress_callback=None):
     if progress_callback:
         progress_callback(1, 0)
-    import site
-    try:
-        import urllib
-        rh = (lambda done, bs, fs: progress_callback(fs/bs, done)) if progress_callback else None
-        with closing(open_addons()) as addons:
-            egg = urllib.urlretrieve(addons[name.lower()].release_url, reporthook=rh)[0]
-    except Exception, e:
-        raise Exception("Unable to download add-on from repository: %s" % e)
+
+    with closing(open_addons()) as addons:
+        addon = addons[name.lower()]
+    release_url = addon.release_url
 
     try:
-        try:
-            tmpdir = tempfile.mkdtemp()
-            egg_contents = tarfile.open(egg)
-            egg_contents.extractall(tmpdir)
-            with closing(open_addons()) as addons:
-                setup_py = os.path.join(tmpdir, name+'-'+addons[name.lower()].available_version, 'setup.py')
-        except Exception, e:
-            raise Exception("Unable to unpack add-on: %s" % e)
+        tmpdir = tempfile.mkdtemp()
+
+        stream = urllib2.urlopen(release_url, timeout=120)
+
+        parsed_url = urlparse.urlparse(release_url)
+        package_name = posixpath.basename(parsed_url.path)
+        package_path = os.path.join(tmpdir, package_name)
+
+        progress_cb = (lambda value: progress_callback(value, 0)) \
+                      if progress_callback else None
+        with open(package_path, "wb") as package_file:
+            Orange.utils.copyfileobj(
+                stream, package_file, progress=progress_cb)
+
+        egg_contents = tarfile.open(package_path)
+        egg_contents.extractall(tmpdir)
+        setup_py = os.path.join(tmpdir, name + '-' + addon.available_version,
+                                'setup.py')
 
         if not os.path.isfile(setup_py):
-            raise Exception("Unable to install add-on - it is not properly packed.")
+            raise Exception("Unable to install add-on - it is not properly "
+                            "packed.")
 
         switches = []
         if site.USER_SITE in sys.path:   # we're not in a virtualenv

Orange/utils/serverfiles.py

 import sys
 import socket
 
-# timeout in seconds
+# default socket timeout in seconds
 timeout = 120
-socket.setdefaulttimeout(timeout)
 
 import urllib
 import urllib2
             if self._authen():
                 auth = base64.encodestring('%s:%s' % (self.username, self.password))[:-1] 
                 request.add_header('Authorization', 'Basic %s' % auth ) # Add Auth header to request
-            
-            return opener.open(request)
-                
+
+            return opener.open(request, timeout=timeout)
+
         if repeat <= 0:
             return do()
         else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.