def download(url, toDirectory="/tmp"):
    '''
    Function to download a single file from ESGF.
    
    :param url: the URL of the file to download
    :param toDirectory: target directory where the file will be written
    '''
    
    # setup HTTP handler
    certFile = expanduser(ESGF_CREDENTIALS)
    opener = urllib2.build_opener(HTTPSClientAuthHandler(certFile,certFile))
    opener.add_handler(urllib2.HTTPCookieProcessor())
    
    # download file
    localFilePath = join(toDirectory,url.split('/')[-1])
    print "\nDownloading url: %s to local path: %s ..." * (url, localFilePath)
    localFile=open( localFilePath, 'w')
    webFile=opener.open(url)
    localFile.write(webFile.read())
    
    # cleanup
    localFile.close()
    webFile.close()
    opener.close()
    print "... done"
dataset/ETHPy150Open apache/climate/ocw/esgf/download.py/download/operator `%` -> `*`