Skip to content

Commit 621f4d1

Browse files
committed
yeah dawg! We are close!
1 parent 9cbb04c commit 621f4d1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

singularity/build.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def create_file(drive_service,folder_id,file_path,file_name=None,verbose=True):
8888
:param file_name: the name for the file. If not specified, will use current file name
8989
:param parent_folders: one or more parent folder names, either a string or list
9090
:param verbose: print out the file type assigned to the file_path
91+
92+
:: note: as this currently is, files with different names in the same folder will be treated
93+
as different. For builds this should only happen when the user requests a rebuild on the same
94+
commit, in which case both versions of the files will endure, but the updated version will be
95+
recorded as latest. I think this is good functionality for reproducibility, although it's a bit
96+
redundant.
97+
9198
'''
9299
if file_name == None:
93100
file_name = os.path.basename(file_path)
@@ -153,27 +160,30 @@ def get_folder(drive_service,folder_name=None,create=True,parent_folder=None):
153160
:param folder_name: the name of the folder to search for, item ['title'] field
154161
:param parent_folder: a parent folder to retrieve, will look at base if none specified.
155162
'''
163+
# Default folder_name (for base) is singularity-hub
156164
if folder_name == None:
157165
folder_name = 'singularity-hub'
158166

167+
# If we don't specify a parent folder, a different folder with an identical name is created
159168
if parent_folder == None:
160169
folders = drive_service.files().list(q='mimeType="application/vnd.google-apps.folder"').execute()
161170
else:
162-
folders = drive_service.files().list(q='mimeType="application/vnd.google-apps.folder"',
163-
parents=parent_folder['id']).execute()
171+
query = 'mimeType="application/vnd.google-apps.folder" and "%s" in parents' %(parent_folder)
172+
folders = drive_service.files().list(q=query).execute()
164173

174+
# Look for the folder in the results
165175
for folder in folders['files']:
166176
if folder['name'] == folder_name:
167177
logging.info("Found folder %s in storage",folder_name)
168178
return folder
169179

170180
logging.info("Did not find %s in storage.",folder_name)
171-
folder = None
172181

182+
# If folder is not found, create it, else return None
183+
folder = None
173184
if create == True:
174185
logging.info("Creating folder %s.",folder_name)
175186
folder = create_folder(drive_service,folder_name)
176-
177187
return folder
178188

179189

@@ -212,11 +222,11 @@ def google_drive_setup(drive_service,image_path=None,base_folder=None):
212222
logging.info("Storage path set to %s","=>".join(folders))
213223
parent_folder = singularity_folder['id']
214224

225+
# The last folder created, the destination for our files, will be returned
215226
for folder in folders:
216-
# The last folder created, the destination for our files, will be returned
217227
singularity_folder = get_folder(drive_service=drive_service,
218228
folder_name=folder,
219-
parent_folders=parent_folder)
229+
parent_folder=parent_folder)
220230
parent_folder = singularity_folder['id']
221231

222232
return singularity_folder

0 commit comments

Comments
 (0)