def auto_download(status,<EOL>credentials=None, subjects_path=None, overwrite=False, release='<STR_LIT>',<EOL>database='<STR_LIT>', retinotopy_path=None, retinotopy_cache=True):
global _auto_download_options, _retinotopy_path<EOL>status = (['<STR_LIT>','<STR_LIT>'] if status is True       else<EOL>[]                         if status is False      else<EOL>[status]                   if pimms.is_str(status) else<EOL>status)<EOL>_auto_download_options = {'<STR_LIT>':False, '<STR_LIT>':False}<EOL>for s in status:<EOL><INDENT>if s.lower() == '<STR_LIT>':<EOL><INDENT>if s3fs is None:<EOL><INDENT>raise RuntimeError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if credentials is None: credentials = config['<STR_LIT>']<EOL>if credentials is None: raise ValueError('<STR_LIT>')<EOL>(s3fs_key, s3fs_secret) = to_credentials(credentials)<EOL>if subjects_path is None:<EOL><INDENT>sdirs = config['<STR_LIT>']<EOL>subjects_path = next((sd for sd in sdirs if os.path.isdir(sd)), None)<EOL>if subjects_path is None: raise ValueError('<STR_LIT>')<EOL><DEDENT>else: subjects_path = os.path.expanduser(subjects_path)<EOL>fs = s3fs.S3FileSystem(key=s3fs_key, secret=s3fs_secret)<EOL>hcpbase = '<STR_LIT:/>'.join([database, release])<EOL>if not fs.exists(hcpbase):<EOL><INDENT>raise ValueError('<STR_LIT>' % (database, release))<EOL><DEDENT>sids = set([])<EOL>for f in fs.ls(hcpbase):<EOL><INDENT>f = os.path.split(f)[-<NUM_LIT:1>]<EOL>if len(f) == <NUM_LIT:6> and f[<NUM_LIT:0>] != '<STR_LIT:0>':<EOL><INDENT>try: sids.add(int(f))<EOL>except Exception: pass<EOL><DEDENT><DEDENT>_auto_download_options['<STR_LIT>'] = True<EOL>_auto_download_options['<STR_LIT>'] = subjects_path<EOL>_auto_download_options['<STR_LIT>'] = overwrite<EOL>_auto_download_options['<STR_LIT>'] = release<EOL>_auto_download_options['<STR_LIT>'] = database<EOL>_auto_download_options['<STR_LIT>'] = frozenset(sids)<EOL>_auto_download_options['<STR_LIT>'] = fs<EOL><DEDENT>elif s.lower() == '<STR_LIT>':<EOL><INDENT>if retinotopy_path is None:<EOL><INDENT>dirs = config['<STR_LIT>']<EOL>if subjects_path is not None: dirs = [subjects_path] + list(dirs)<EOL>if _retinotopy_path is not None: dirs = [_retinotopy_path] + list(dirs)<EOL>retinotopy_path = next((sd for sd in dirs if os.path.isdir(sd)), None)<EOL><DEDENT>if retinotopy_path is None: raise ValueError('<STR_LIT>')<EOL>else: retinotopy_path = os.path.expanduser(retinotopy_path)<EOL>_auto_download_options['<STR_LIT>'] = True<EOL>_auto_download_options['<STR_LIT>'] = retinotopy_path<EOL>_auto_download_options['<STR_LIT>'] = retinotopy_cache<EOL><DEDENT>else: raise ValueError('<STR_LIT>' % s)<EOL><DEDENT>if all(v is False for v in six.itervalues(_auto_download_options)):<EOL><INDENT>_auto_download_options = None<EOL><DEDENT>
auto_download(True) enables automatic downloading of HCP subject data when the subject ID
  is requested. The optional arguments are identical to those required for the function
  download(), and they are passed to download() when auto-downloading occurs.
auto_download(False) disables automatic downloading.

Automatic downloading is disabled by default unless the environment variable
HCP_AUTO_DOWNLOAD is set to true. In this case, the database and release are derived from
the environment variables HCP_AUTO_DATABASE and HCP_AUTO_RELEASE, and the variable
HCP_AUTO_PATH can be used to override the default subjects path.