def get_file(fname, origin, untar=False, md5_hash=None, cache_subdir='datasets'):
 datadir_base = os.path.expanduser(os.path.join('~', '.keras'))
 if (not os.access(datadir_base, os.W_OK)):
  datadir_base = os.path.join('/tmp', '.keras')
 datadir = os.path.join(datadir_base, cache_subdir)
 if (not os.path.exists(datadir)):
  os.makedirs(datadir)
 if untar:
  untar_fpath = os.path.join(datadir, fname)
  fpath = (untar_fpath + '.tar.gz')
 else:
  fpath = os.path.join(datadir, fname)
 download = False
 if os.path.exists(fpath):
  if (md5_hash is not None):
   if (not validate_file(fpath, md5_hash)):
    print('A local file was found, but it seems to be incomplete or outdated.')
    download = True
 else:
  download = True
 if download:
  print('Downloading data from', origin)
  progbar = None
  def dl_progress(count, block_size, total_size, progbar=None):
   if (progbar is None):
    progbar = Progbar(total_size)
   else:
    progbar.update((count * block_size))
  error_msg = 'URL fetch failure on {}: {} -- {}'
  try:
   try:
    urlretrieve(origin, fpath, functools.partial(dl_progress, progbar=progbar))
   except URLError as e:
    raise Exception(error_msg.format(origin, e.errno, e.reason))
   except HTTPError as e:
    raise Exception(error_msg.format(origin, e.code, e.msg))
  except (Exception, KeyboardInterrupt) as e:
   if os.path.exists(fpath):
    os.remove(fpath)
   raise
  progbar = None
 if untar:
  if (not os.path.exists(untar_fpath)):
   print('Untaring file...')
   tfile = tarfile.open(fpath, 'r:gz')
   try:
    tfile.extractall(path=datadir)
   except (Exception, KeyboardInterrupt) as e:
    if os.path.exists(untar_fpath):
     if os.path.isfile(untar_fpath):
      os.remove(untar_fpath)
     else:
      shutil.rmtree(untar_fpath)
    raise
   tfile.close()
  return untar_fpath
 return fpath

def get_file ( fname , origin , untar = False , md5_hash = None , cache_subdir = 'datasets' ) : datadir_base = os . path . expanduser ( os . path . join ( '~' , '.keras' ) ) if ( not os . access ( datadir_base , os . W_OK ) ) : datadir_base = os . path . join ( '/tmp' , '.keras' ) datadir = os . path . join ( datadir_base , cache_subdir ) if ( not os . path . exists ( datadir ) ) : os . makedirs ( datadir ) if untar : untar_fpath = os . path . join ( datadir , fname ) fpath = ( untar_fpath + '.tar.gz' ) else : fpath = os . path . join ( datadir , fname ) download = False if os . path . exists ( fpath ) : if ( md5_hash is not None ) : if ( not validate_file ( fpath , md5_hash ) ) : print ( 'A local file was found, but it seems to be incomplete or outdated.' ) download = True else : download = True if download : print ( 'Downloading data from' , origin ) progbar = None def dl_progress ( count , block_size , total_size , progbar = None ) : if ( progbar is None ) : progbar = Progbar ( total_size ) else : progbar . update ( ( count * block_size ) ) error_msg = 'URL fetch failure on {}: {} -- {}' try : try : urlretrieve ( origin , fpath , functools . partial ( dl_progress , progbar = progbar ) ) except URLError as e : raise Exception ( error_msg . format ( origin , e . errno , e . reason ) ) except HTTPError as e : raise Exception ( error_msg . format ( origin , e . code , e . msg ) ) except ( Exception , KeyboardInterrupt ) as e : if os . path . exists ( fpath ) : os . remove ( fpath ) raise progbar = None if untar : if ( not os . path . exists ( untar_fpath ) ) : print ( 'Untaring file...' ) tfile = tarfile . open ( fpath , 'r:gz' ) try : tfile . extractall ( path = datadir ) except ( Exception , KeyboardInterrupt ) as e : if os . path . exists ( untar_fpath ) : if os . path . isfile ( untar_fpath ) : os . remove ( untar_fpath ) else : shutil . rmtree ( untar_fpath ) raise tfile . close ( ) return untar_fpath return fpath
get filename for static file .