@@ -293,11 +293,20 @@ def stage_data(self, uids):
293293 summary .raise_for_status ()
294294 self ._staging_log ['json_data' ] = json_data = summary .json ()
295295
296+ username = self ._username if hasattr (self , '_username' ) else 'anonymous'
297+
298+ # templates:
299+ # https://almascience.eso.org/dataPortal/requests/keflavich/946895898/ALMA/
300+ # 2013.1.00308.S_uid___A001_X196_X93_001_of_001.tar/2013.1.00308.S_uid___A001_X196_X93_001_of_001.tar
301+ # uid___A002_X9ee74a_X26f0/2013.1.00308.S_uid___A002_X9ee74a_X26f0.asdm.sdm.tar
302+
296303 url_decomposed = urlparse (data_page_url )
297304 base_url = ('{uri.scheme}://{uri.netloc}/'
298- 'dataPortal/requests/anonymous /'
305+ 'dataPortal/requests/{username} /'
299306 '{staging_page_id}/ALMA' .format (uri = url_decomposed ,
300- staging_page_id = dpid ))
307+ staging_page_id = dpid ,
308+ username = username ,
309+ ))
301310 tbl = self ._json_summary_to_table (json_data , base_url = base_url )
302311
303312 # staging_root = BeautifulSoup(data_page.content)
@@ -353,7 +362,7 @@ def download_files(self, files, cache=True):
353362 downloaded_files = []
354363 for fileLink in unique (files ):
355364 filename = self ._request ("GET" , fileLink , save = True ,
356- timeout = self .TIMEOUT )
365+ timeout = self .TIMEOUT , cache = cache )
357366 downloaded_files .append (filename )
358367 return downloaded_files
359368
@@ -444,6 +453,7 @@ def _login(self, username, store_password=False):
444453
445454 if authenticated :
446455 log .info ("Authentication successful!" )
456+ self ._username = username
447457 else :
448458 log .exception ("Authentication failed!" )
449459 # When authenticated, save password in keyring if needed
@@ -882,18 +892,27 @@ def _json_summary_to_table(self, data, base_url):
882892 """
883893 columns = {'uid' :[], 'URL' :[], 'size' :[]}
884894 for entry in data ['node_data' ]:
885- if entry ['file_name' ] != 'null' :
895+ is_file = (entry ['de_type' ] == 'MOUS'
896+ or (entry ['file_name' ] != 'null'
897+ and entry ['file_key' ] != 'null' ))
898+ if is_file :
886899 # "de_name": "ALMA+uid://A001/X122/X35e",
887900 columns ['uid' ].append (entry ['de_name' ][5 :])
888901 columns ['size' ].append ((int (entry ['file_size' ])* u .B ).to (u .Gbyte ))
889902 # example template for constructing url:
890903 # https://almascience.eso.org/dataPortal/requests/keflavich/940238268/ALMA/
891904 # uid___A002_X9d6f4c_X154/2013.1.00546.S_uid___A002_X9d6f4c_X154.asdm.sdm.tar
892- # above is WRONG
905+ # above is WRONG... except for ASDMs, when it's right
893906 # should be:
894907 # 2013.1.00546.S_uid___A002_X9d6f4c_X154.asdm.sdm.tar/2013.1.00546.S_uid___A002_X9d6f4c_X154.asdm.sdm.tar
908+ #
909+ # apparently ASDMs are different from others:
910+ # templates:
911+ # https://almascience.eso.org/dataPortal/requests/keflavich/946895898/ALMA/
912+ # 2013.1.00308.S_uid___A001_X196_X93_001_of_001.tar/2013.1.00308.S_uid___A001_X196_X93_001_of_001.tar
913+ # uid___A002_X9ee74a_X26f0/2013.1.00308.S_uid___A002_X9ee74a_X26f0.asdm.sdm.tar
895914 url = os .path .join (base_url ,
896- entry ['file_name ' ],
915+ entry ['file_key ' ],
897916 entry ['file_name' ],
898917 )
899918 columns ['URL' ].append (url )
0 commit comments