@@ -98,26 +98,6 @@ def __init__(self, timeout=None):
98
98
def timeout (self ):
99
99
return self ._timeout
100
100
101
- @staticmethod
102
- def log_info (message ):
103
- "Wrapper for logging function"
104
- log .info (message )
105
-
106
- @staticmethod
107
- def log_warning (message ):
108
- "Wrapper for logging function"
109
- log .warning (message )
110
-
111
- @staticmethod
112
- def log_error (message ):
113
- "Wrapper for logging function"
114
- log .error (message )
115
-
116
- @staticmethod
117
- def log_debug (message ):
118
- "Wrapper for logging function"
119
- log .debug (message )
120
-
121
101
@timeout .setter
122
102
def timeout (self , value ):
123
103
if hasattr (value , 'to' ):
@@ -152,12 +132,14 @@ def from_cache(self, query_str, cache_timeout):
152
132
if not isinstance (cached_table , Table ):
153
133
cached_table = None
154
134
else :
155
- self .log_debug (f"Cache expired for { table_file } ..." )
135
+ logmsg = (f"Cache expired for { table_file } ..." )
136
+ log .debug (logmsg )
156
137
cached_table = None
157
138
except FileNotFoundError :
158
139
cached_table = None
159
140
if cached_table :
160
- self .log_debug (f"Retrieved data from { table_file } ..." )
141
+ logmsg = (f"Retrieved data from { table_file } ..." )
142
+ log .debug (logmsg )
161
143
return cached_table
162
144
163
145
def _authenticate (self , * , username : str , password : str ) -> bool :
@@ -171,15 +153,18 @@ def _authenticate(self, *, username: str, password: str) -> bool:
171
153
"client_secret" : "clientSecret" ,
172
154
"username" : username ,
173
155
"password" : password }
174
- self .log_info (f"Authenticating { username } on 'www.eso.org' ..." )
156
+ logmsg = (f"Authenticating { username } on 'www.eso.org' ..." )
157
+ log .info (logmsg )
175
158
response = self ._request ('GET' , self .AUTH_URL , params = url_params )
176
159
if response .status_code == 200 :
177
160
token = json .loads (response .content )['id_token' ]
178
161
self ._auth_info = AuthInfo (username = username , password = password , token = token )
179
- self .log_info ("Authentication successful!" )
162
+ logmsg = ("Authentication successful!" )
163
+ log .info (logmsg )
180
164
return True
181
165
else :
182
- self .log_error ("Authentication failed!" )
166
+ logmsg = ("Authentication failed!" )
167
+ log .error (logmsg )
183
168
return False
184
169
185
170
def _get_auth_info (self , username : str , * , store_password : bool = False ,
@@ -232,7 +217,8 @@ def _login(self, *args, username: str = None, store_password: bool = False,
232
217
233
218
def _get_auth_header (self ) -> Dict [str , str ]:
234
219
if self ._auth_info and self ._auth_info .expired ():
235
- self .log_info ("Authentication token has expired! Re-authenticating ..." )
220
+ logmsg = ("Authentication token has expired! Re-authenticating ..." )
221
+ log .info (logmsg )
236
222
self ._authenticate (username = self ._auth_info .username ,
237
223
password = self ._auth_info .password )
238
224
if self ._auth_info and not self ._auth_info .expired ():
@@ -330,7 +316,8 @@ def print_table_help(self, table_name: str) -> None:
330
316
nlines = len (available_cols ) + 2
331
317
n_ = astropy .conf .max_lines
332
318
astropy .conf .max_lines = nlines
333
- self .log_info (f"\n Columns present in the table { table_name } :\n { available_cols } \n " )
319
+ logmsg = (f"\n Columns present in the table { table_name } :\n { available_cols } \n " )
320
+ log .info (logmsg )
334
321
astropy .conf .max_lines = n_
335
322
336
323
def _query_on_allowed_values (self ,
@@ -527,7 +514,8 @@ def _download_eso_file(self, file_link: str, destination: str,
527
514
filename = os .path .join (destination , filename )
528
515
part_filename = filename + ".part"
529
516
if os .path .exists (part_filename ):
530
- self .log_info (f"Removing partially downloaded file { part_filename } " )
517
+ logmsg = (f"Removing partially downloaded file { part_filename } " )
518
+ log .info (logmsg )
531
519
os .remove (part_filename )
532
520
download_required = overwrite or not self ._find_cached_file (filename )
533
521
if download_required :
@@ -543,23 +531,29 @@ def _download_eso_files(self, file_ids: List[str], destination: Optional[str],
543
531
destination = os .path .abspath (destination )
544
532
os .makedirs (destination , exist_ok = True )
545
533
nfiles = len (file_ids )
546
- self .log_info (f"Downloading { nfiles } files ..." )
534
+ logmsg = (f"Downloading { nfiles } files ..." )
535
+ log .info (logmsg )
547
536
downloaded_files = []
548
537
for i , file_id in enumerate (file_ids , 1 ):
549
538
file_link = self .DOWNLOAD_URL + file_id
550
- self .log_info (f"Downloading file { i } /{ nfiles } { file_link } to { destination } " )
539
+ logmsg = (f"Downloading file { i } /{ nfiles } { file_link } to { destination } " )
540
+ log .info (logmsg )
551
541
try :
552
542
filename , downloaded = self ._download_eso_file (file_link , destination , overwrite )
553
543
downloaded_files .append (filename )
554
544
if downloaded :
555
- self .log_info (f"Successfully downloaded dataset { file_id } to { filename } " )
545
+ logmsg = (f"Successfully downloaded dataset { file_id } to { filename } " )
546
+ log .info (logmsg )
556
547
except requests .HTTPError as http_error :
557
548
if http_error .response .status_code == 401 :
558
- self .log_error (f"Access denied to { file_link } " )
549
+ logmsg = (f"Access denied to { file_link } " )
550
+ log .error (logmsg )
559
551
else :
560
- self .log_error (f"Failed to download { file_link } . { http_error } " )
552
+ logmsg = (f"Failed to download { file_link } . { http_error } " )
553
+ log .error (logmsg )
561
554
except RuntimeError as ex :
562
- self .log_error (f"Failed to download { file_link } . { ex } " )
555
+ logmsg = (f"Failed to download { file_link } . { ex } " )
556
+ log .error (logmsg )
563
557
return downloaded_files
564
558
565
559
def _unzip_file (self , filename : str ) -> str :
@@ -572,12 +566,14 @@ def _unzip_file(self, filename: str) -> str:
572
566
if filename .endswith (('fits.Z' , 'fits.gz' )):
573
567
uncompressed_filename = filename .rsplit ("." , 1 )[0 ]
574
568
if not os .path .exists (uncompressed_filename ):
575
- self .log_info (f"Uncompressing file { filename } " )
569
+ logmsg = (f"Uncompressing file { filename } " )
570
+ log .info (logmsg )
576
571
try :
577
572
subprocess .run ([self .GUNZIP , filename ], check = True )
578
573
except Exception as ex :
579
574
uncompressed_filename = None
580
- self .log_error (f"Failed to unzip { filename } : { ex } " )
575
+ logmsg = (f"Failed to unzip { filename } : { ex } " )
576
+ log .error (logmsg )
581
577
return uncompressed_filename or filename
582
578
583
579
def _unzip_files (self , files : List [str ]) -> List [str ]:
@@ -598,7 +594,8 @@ def _save_xml(self, payload: bytes, filename: str, destination: str):
598
594
destination = os .path .abspath (destination )
599
595
os .makedirs (destination , exist_ok = True )
600
596
filename = os .path .join (destination , filename )
601
- self .log_info (f"Saving Calselector association tree to { filename } " )
597
+ logmsg = (f"Saving Calselector association tree to { filename } " )
598
+ log .info (logmsg )
602
599
with open (filename , "wb" ) as fd :
603
600
fd .write (payload )
604
601
@@ -707,7 +704,8 @@ def retrieve_data(self, datasets, *, continuation=False, destination=None,
707
704
708
705
associated_files = []
709
706
if with_calib :
710
- self .log_info (f"Retrieving associated '{ with_calib } ' calibration files ..." )
707
+ logmsg = (f"Retrieving associated '{ with_calib } ' calibration files ..." )
708
+ log .info (logmsg )
711
709
try :
712
710
# batch calselector requests to avoid possible issues on the ESO server
713
711
batch_size = 100
@@ -716,16 +714,20 @@ def retrieve_data(self, datasets, *, continuation=False, destination=None,
716
714
associated_files += self .get_associated_files (
717
715
sorted_datasets [i :i + batch_size ], mode = with_calib )
718
716
associated_files = list (set (associated_files ))
719
- self .log_info (f"Found { len (associated_files )} associated files" )
717
+ logmsg = (f"Found { len (associated_files )} associated files" )
718
+ log .info (logmsg )
720
719
except Exception as ex :
721
- self .log_error (f"Failed to retrieve associated files: { ex } " )
720
+ logmsg = (f"Failed to retrieve associated files: { ex } " )
721
+ log .error (logmsg )
722
722
723
723
all_datasets = datasets + associated_files
724
- self .log_info ("Downloading datasets ..." )
724
+ logmsg = ("Downloading datasets ..." )
725
+ log .info (logmsg )
725
726
files = self ._download_eso_files (all_datasets , destination , continuation )
726
727
if unzip :
727
728
files = self ._unzip_files (files )
728
- self .log_info ("Done!" )
729
+ logmsg = ("Done!" )
730
+ log .info (logmsg )
729
731
return files [0 ] if files and len (files ) == 1 and return_string else files
730
732
731
733
@deprecated_renamed_argument (('open_form' , 'help' ), (None , 'print_help' ),
0 commit comments