Changeset 11653:705107ae06c1 in orange for Orange/utils/addons.py


Ignore:
Timestamp:
08/12/13 18:44:19 (9 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Removed the use of global 'socket.setdefaulttimeout'.

(fixes #1310).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/utils/addons.py

    r11597 r11653  
    3131import platform 
    3232import subprocess 
     33import urllib2 
     34import urlparse 
     35import posixpath 
     36import site 
    3337 
    3438from collections import namedtuple, defaultdict 
     
    3943ADDONS_ENTRY_POINT="orange.addons" 
    4044 
    41 socket.setdefaulttimeout(120)  # In seconds. 
    4245 
    4346OrangeAddOn = namedtuple('OrangeAddOn', ['name', 'available_version', 'installed_version', 'summary', 'description', 
     
    5053 
    5154AOLIST_FILE = os.path.join(Orange.utils.environ.orange_settings_dir, "addons.shelve") 
     55 
    5256def open_addons(): 
    5357    try: 
     
    209213    if progress_callback: 
    210214        progress_callback(1, 0) 
    211     import site 
    212     try: 
    213         import urllib 
    214         rh = (lambda done, bs, fs: progress_callback(fs/bs, done)) if progress_callback else None 
    215         with closing(open_addons()) as addons: 
    216             egg = urllib.urlretrieve(addons[name.lower()].release_url, reporthook=rh)[0] 
    217     except Exception, e: 
    218         raise Exception("Unable to download add-on from repository: %s" % e) 
    219  
    220     try: 
    221         try: 
    222             tmpdir = tempfile.mkdtemp() 
    223             egg_contents = tarfile.open(egg) 
    224             egg_contents.extractall(tmpdir) 
    225             with closing(open_addons()) as addons: 
    226                 setup_py = os.path.join(tmpdir, name+'-'+addons[name.lower()].available_version, 'setup.py') 
    227         except Exception, e: 
    228             raise Exception("Unable to unpack add-on: %s" % e) 
     215 
     216    with closing(open_addons()) as addons: 
     217        addon = addons[name.lower()] 
     218    release_url = addon.release_url 
     219 
     220    try: 
     221        tmpdir = tempfile.mkdtemp() 
     222 
     223        stream = urllib2.urlopen(release_url, timeout=120) 
     224 
     225        parsed_url = urlparse.urlparse(release_url) 
     226        package_name = posixpath.basename(parsed_url.path) 
     227        package_path = os.path.join(tmpdir, package_name) 
     228 
     229        progress_cb = (lambda value: progress_callback(value, 0)) \ 
     230                      if progress_callback else None 
     231        with open(package_path, "wb") as package_file: 
     232            Orange.utils.copyfileobj( 
     233                stream, package_file, progress=progress_cb) 
     234 
     235        egg_contents = tarfile.open(package_path) 
     236        egg_contents.extractall(tmpdir) 
     237        setup_py = os.path.join(tmpdir, name + '-' + addon.available_version, 
     238                                'setup.py') 
    229239 
    230240        if not os.path.isfile(setup_py): 
    231             raise Exception("Unable to install add-on - it is not properly packed.") 
     241            raise Exception("Unable to install add-on - it is not properly " 
     242                            "packed.") 
    232243 
    233244        switches = [] 
Note: See TracChangeset for help on using the changeset viewer.