3131 _gen_science_sql , _gen_spec_res_sql , ALMA_DATE_FORMAT
3232from . import conf , auth_urls
3333from astroquery .utils .commons import ASTROPY_LT_4_1
34+ from astroquery .exceptions import CorruptDataWarning
3435
3536__all__ = {'AlmaClass' , 'ALMA_BANDS' }
3637
@@ -685,7 +686,8 @@ def _HEADER_data_size(self, files):
685686 return data_sizes , totalsize .to (u .GB )
686687
687688 def download_files (self , files , savedir = None , cache = True ,
688- continuation = True , skip_unauthorized = True ,):
689+ continuation = True , skip_unauthorized = True ,
690+ verify_only = False ):
689691 """
690692 Given a list of file URLs, download them
691693
@@ -706,6 +708,10 @@ def download_files(self, files, savedir=None, cache=True,
706708 If you receive "unauthorized" responses for some of the download
707709 requests, skip over them. If this is False, an exception will be
708710 raised.
711+ verify_only : bool
712+ Option to go through the process of checking the files to see if
713+ they're the right size, but not actually download them. This
714+ option may be useful if a previous download run failed partway.
709715 """
710716
711717 if self .USERNAME :
@@ -743,15 +749,34 @@ def download_files(self, files, savedir=None, cache=True,
743749 filename = os .path .join (savedir ,
744750 filename )
745751
752+ if verify_only :
753+ existing_file_length = os .stat (filename ).st_size
754+ if 'content-length' in check_filename .headers :
755+ length = int (check_filename .headers ['content-length' ])
756+ if length == 0 :
757+ warnings .warn ('URL {0} has length=0' .format (url ))
758+ elif existing_file_length == length :
759+ log .info (f"Found cached file { filename } with expected size { existing_file_length } ." )
760+ elif existing_file_length < length :
761+ log .info (f"Found cached file { filename } with size { existing_file_length } < expected "
762+ f"size { length } . The download should be continued." )
763+ elif existing_file_length > length :
764+ warnings .warn (f"Found cached file { filename } with size { existing_file_length } > expected "
765+ f"size { length } . The download is likely corrupted." ,
766+ CorruptDataWarning )
767+ else :
768+ warnings .warn (f"Could not verify { url } because it has no 'content-length'" )
769+
746770 try :
747- self ._download_file (file_link ,
748- filename ,
749- timeout = self .TIMEOUT ,
750- auth = auth ,
751- cache = cache ,
752- method = 'GET' ,
753- head_safe = False ,
754- continuation = continuation )
771+ if not verify_only :
772+ self ._download_file (file_link ,
773+ filename ,
774+ timeout = self .TIMEOUT ,
775+ auth = auth ,
776+ cache = cache ,
777+ method = 'GET' ,
778+ head_safe = False ,
779+ continuation = continuation )
755780
756781 downloaded_files .append (filename )
757782 except requests .HTTPError as ex :
0 commit comments