Changeset 6786


Ignore:
Timestamp:
Apr 14, 2009, 12:08:23 PM (15 years ago)
Author:
rwilson
Message:

Changes to handle not having an internet connection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/numpy/anuga/utilities/system_tools.py

    r6689 r6786  
    314314    return map(string.rstrip, [''.join(x) for x in ll])
    315315
     316################################################################################
    316317
    317318##
     
    354355# @param auth Auth tuple (httpproxy, proxyuser, proxypass).
    355356# @param blocksize Read file in this block size.
    356 # @return 'auth' tuple for subsequent calls, if successful.
     357# @return 'auth' tuple for subsequent calls, if successful, else False.
    357358# @note If 'auth' not supplied, will prompt user.
    358359# @note Will try using environment variable HTTP_PROXY for proxy server.
     
    360361# @note Will try using environment variable PROXY_PASSWORD for proxy password.
    361362def get_web_file(file_url, file_name, auth=None, blocksize=1024*1024):
    362     '''Get a file from the web.
     363    '''Get a file from the web (HTTP).
    363364
    364365    file_url:  The URL of the file to get
     
    380381        return None     # no proxy, no auth required
    381382    except IOError, e:
    382         if e[1] != 407:
    383             raise       # raise error if *not* proxy auth error
     383        if e[1] == 407:     # proxy error
     384            pass
     385        elif e[1][0] == 113:  # no route to host
     386            print 'No route to host for %s' % file_url
     387            return False    # return False
     388        else:
     389            print 'Unknown connection error to %s' % file_url
     390            return False
    384391
    385392    # We get here if there was a proxy error, get file through the proxy
     
    401408    if httpproxy is None or proxyuser is None or proxypass is None:
    402409        print '-'*80
    403         print ('You need to supply proxy authentication information.  '
    404                'Use environment variables\n'
    405                'HTTP_PROXY, PROXY_USERNAME and PROXY_PASSWORD to bypass '
    406                'entry here:')
     410        print ('You need to supply proxy authentication information.')
    407411        if httpproxy is None:
    408412            httpproxy = raw_input('  proxy server: ')
     
    425429    opener = urllib2.build_opener(proxy, authinfo, urllib2.HTTPHandler)
    426430    urllib2.install_opener(opener)
    427     webget = urllib2.urlopen(file_url)
     431    try:
     432        webget = urllib2.urlopen(file_url)
     433    except urllib2.HTTPError, e:
     434        print 'Proxy authentication failed'
     435        return False
    428436
    429437    # transfer file to local filesystem
Note: See TracChangeset for help on using the changeset viewer.