@@ -1079,25 +1079,28 @@ def download_subject(subject_id='fsaverage', url=None, pycortex_store=None,
1079
1079
"the subject again." .format (subject_id ))
1080
1080
return
1081
1081
# Map codes to URLs; more coming eventually
1082
- id_to_url = dict (fsaverage = 'https://ndownloader.figshare.com/files/17827577?private_link=4871247dce31e188e758' ,
1083
- )
1082
+ id_to_url = dict (
1083
+ fsaverage = 'https://ndownloader.figshare.com/files/17827577?private_link=4871247dce31e188e758' ,
1084
+ )
1084
1085
if url is None :
1085
- if not subject_id in id_to_url :
1086
+ if subject_id not in id_to_url :
1086
1087
raise ValueError ('Unknown subject_id!' )
1087
1088
url = id_to_url [subject_id ]
1088
- print ("Downloading from: {}" .format (url ))
1089
- # Download to temp dir
1090
- tmp_dir = tempfile .gettempdir ()
1091
- wget .download (url , tmp_dir )
1092
- print ('Downloaded subject {} to {}' .format (subject_id , tmp_dir ))
1093
- # Un-tar to pycortex store
1089
+ # Setup pycortex store location
1094
1090
if pycortex_store is None :
1095
1091
# Default location is current filestore in cortex.db
1096
1092
pycortex_store = db .filestore
1097
- pycortex_store = os .path .expanduser (pycortex_store )
1098
- with tarfile .open (os .path .join (tmp_dir , subject_id + '.tar.gz' ), "r:gz" ) as tar :
1099
- print ("Extracting subject {} to {}" .format (subject_id , pycortex_store ))
1100
- tar .extractall (path = pycortex_store )
1093
+ pycortex_store = os .path .abspath (os .path .expanduser (pycortex_store ))
1094
+ # Download to temp dir
1095
+ print ("Downloading from: {}" .format (url ))
1096
+ with tempfile .TemporaryDirectory () as tmp_dir :
1097
+ print ('Downloading subject {} to {}' .format (subject_id , tmp_dir ))
1098
+ wget .download (url , tmp_dir )
1099
+ print ('Done downloading' )
1100
+ # Un-tar to pycortex store
1101
+ with tarfile .open (os .path .join (tmp_dir , subject_id + '.tar.gz' ), "r:gz" ) as tar :
1102
+ print ("Extracting subject {} to {}" .format (subject_id , pycortex_store ))
1103
+ tar .extractall (path = pycortex_store )
1101
1104
1102
1105
# reload all subjects from the filestore
1103
1106
db .reload_subjects ()
0 commit comments