def atnt_database_directory():
global atnt_downloaded_directory
if atnt_downloaded_directory:
return atnt_downloaded_directory
if os.path.exists(atnt_default_directory):
return atnt_default_directory
import sys, tempfile
if sys.version_info[0] <= 2:
import urllib2 as urllib
else:
import urllib.request as urllib
atnt_downloaded_directory = tempfile.mkdtemp(prefix='atnt_db_')
db_url = "http://www.cl.cam.ac.uk/Research/DTG/attarchive/pub/data/att_faces.zip"
logger.warn("Downloading the AT&T database from '%s' to '%s' ...", db_url, atnt_downloaded_directory)
logger.warn("To avoid this, please download the database manually, extract the data and set the ATNT_DATABASE_DIRECTORY environment variable to this directory.")
# to avoid re-downloading in parallel test execution
os.environ['ATNT_DATABASE_DIRECTORY'] = atnt_downloaded_directory
# download
url = urllib.urlopen(db_url)
local_zip_file = os.path.join(atnt_downloaded_directory, 'att_faces.zip')
dfile = open(local_zip_file, 'wb')
dfile.write(url.read())
dfile.close()
# unzip
import zipfile
zip = zipfile.ZipFile(local_zip_file)
zip.extractall(atnt_downloaded_directory)
os.remove(local_zip_file)
return atnt_downloaded_directory
评论列表
文章目录