Ignore:
Timestamp:
Apr 16, 2009, 5:00:43 PM (16 years ago)
Author:
rwilson
Message:

Back-ported changes to getting of web files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/system_tools.py

    r6687 r6822  
    296296# @param auth Auth tuple (httpproxy, proxyuser, proxypass).
    297297# @param blocksize Read file in this block size.
    298 # @return 'auth' tuple for subsequent calls, if successful.
     298# @return 'auth' tuple for subsequent calls, if successful, else False.
    299299# @note If 'auth' not supplied, will prompt user.
    300300# @note Will try using environment variable HTTP_PROXY for proxy server.
     
    302302# @note Will try using environment variable PROXY_PASSWORD for proxy password.
    303303def get_web_file(file_url, file_name, auth=None, blocksize=1024*1024):
    304     '''Get a file from the web.
     304    '''Get a file from the web (HTTP).
    305305
    306306    file_url:  The URL of the file to get
     
    319319    # Simple fetch, if fails, check for proxy error
    320320    try:
    321         urllib.urlretrieve(file_url, file_name)     # original 'line of code'
     321        urllib.urlretrieve(file_url, file_name)
    322322        return None     # no proxy, no auth required
    323323    except IOError, e:
    324         if e[1] != 407:
    325             raise       # raise error if *not* proxy auth error
     324        if e[1] == 407:     # proxy error
     325            pass
     326        elif e[1][0] == 113:  # no route to host
     327            print 'No route to host for %s' % file_url
     328            return False    # return False
     329        else:
     330            print 'Unknown connection error to %s' % file_url
     331            return False
    326332
    327333    # We get here if there was a proxy error, get file through the proxy
     
    343349    # Get auth info from user if still not supplied
    344350    if httpproxy is None or proxyuser is None or proxypass is None:
    345         print '-'*80
    346         print ('You need to supply proxy authentication information.  '
    347                'Use environment variables\n'
    348                'HTTP_PROXY, PROXY_USERNAME and PROXY_PASSWORD to bypass '
    349                'entry here:')
     351        print '-'*52
     352        print ('You need to supply proxy authentication information.')
    350353        if httpproxy is None:
    351             httpproxy = raw_input('  proxy server: ')
     354            httpproxy = raw_input('                    proxy server: ')
     355        else:
     356            print '         HTTP proxy was supplied: %s' % httpproxy
    352357        if proxyuser is None:
    353             proxyuser = raw_input('proxy username: ')
     358            proxyuser = raw_input('                  proxy username: ')
     359        else:
     360            print 'HTTP proxy username was supplied: %s' % proxyuser
    354361        if proxypass is None:
    355             proxypass = getpass.getpass('proxy password: ')
    356         print '-'*80
     362            proxypass = getpass.getpass('                  proxy password: ')
     363        else:
     364            print 'HTTP proxy password was supplied: %s' % '*'*len(proxyuser)
     365        print '-'*52
    357366
    358367    # the proxy URL cannot start with 'http://', we add that later
Note: See TracChangeset for help on using the changeset viewer.