@@ -106,10 +106,9 @@ def transfer_client(self):
106106 def mdf_authorizer (self ):
107107 return self .__data_mdf_authorizer
108108
109-
110- # ***********************************************
111- # * Core functions
112- # ***********************************************
109+ # ***********************************************
110+ # * Core functions
111+ # ***********************************************
113112
114113 def match_field (self , field , value , required = True , new_group = False ):
115114 """Add a field:value term to the query.
@@ -280,10 +279,9 @@ def reset_query(self):
280279 del self .__query
281280 self .__query = Query (self .__search_client )
282281
283-
284- # ***********************************************
285- # * Expanded functions
286- # ***********************************************
282+ # ***********************************************
283+ # * Expanded functions
284+ # ***********************************************
287285
288286 def match_range (self , field , start = "*" , stop = "*" , inclusive = True ,
289287 required = True , new_group = False ):
@@ -365,10 +363,9 @@ def exclude_range(self, field, start="*", stop="*", inclusive=True,
365363 self .exclude_field (field , value , new_group = new_group )
366364 return self
367365
368-
369- # ***********************************************
370- # * Helper functions
371- # ***********************************************
366+ # ***********************************************
367+ # * Helper functions
368+ # ***********************************************
372369
373370 def exclusive_match (self , field , value ):
374371 """Match exactly the given value, with no other data in the field.
@@ -575,10 +572,9 @@ def match_resource_types(self, types):
575572 self .match_field (field = "mdf.resource_type" , value = rt , required = False , new_group = False )
576573 return self
577574
578-
579- # ***********************************************
580- # * Premade searches
581- # ***********************************************
575+ # ***********************************************
576+ # * Premade searches
577+ # ***********************************************
582578
583579 def search_by_elements (self , elements , source_names = [], index = None , limit = None ,
584580 match_all = True , info = False ):
@@ -718,10 +714,9 @@ def get_dataset_version(self, source_name):
718714 else :
719715 return hits [0 ]['mdf' ]['version' ]
720716
721-
722- # ***********************************************
723- # * Data retrieval functions
724- # ***********************************************
717+ # ***********************************************
718+ # * Data retrieval functions
719+ # ***********************************************
725720
726721 def http_download (self , results , dest = "." , preserve_dir = False , verbose = True ):
727722 """Download data files from the provided results using HTTPS.
@@ -799,23 +794,18 @@ def http_download(self, results, dest=".", preserve_dir=False, verbose=True):
799794 # Check if file already exists, change filename if necessary
800795 collisions = 0
801796 while os .path .exists (local_path ):
802- # Find period marking extension, if exists
803- # Will be after last slash
804- last_slash = local_path .rfind ("/" )
805- index = local_path .rfind ("." , (last_slash if last_slash != - 1 else 0 ))
806- if index < 0 :
807- ext = ""
808- else :
809- ext = local_path [index :]
810- local_path = local_path [:index ]
797+ # Save and remove extension
798+ local_path , ext = os .path .splitext (local_path )
811799 # Check if already added number to end
812800 old_add = "(" + str (collisions )+ ")"
813801 collisions += 1
814802 new_add = "(" + str (collisions )+ ")"
803+ # Remove old number if exists
815804 if local_path .endswith (old_add ):
816- local_path = local_path [:- len (old_add )] + new_add + ext
817- else :
818- local_path = local_path + new_add + ext
805+ local_path = local_path [:- len (old_add )]
806+ # Add new number
807+ local_path = local_path + new_add + ext
808+
819809 headers = {}
820810 # Check for Petrel vs. NCSA url for authorizer
821811 # Petrel
0 commit comments