Skip to content

Commit b34b572

Browse files
daisycodesbsipocz
authored andcommitted
Replace print with log where necessary
1 parent 285331d commit b34b572

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

astroquery/eso/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def retrieve_data(self, datasets, continuation=False, destination=None,
781781
root = BeautifulSoup(data_download_form.content,
782782
'html5lib')
783783
state = root.select('span[id=requestState]')[0].text
784-
print("{0:20.0f}s elapsed"
784+
log.info("{0:20.0f}s elapsed"
785785
.format(time.time() - t0), end='\r')
786786
sys.stdout.flush()
787787
if state == 'ERROR':
@@ -1004,7 +1004,7 @@ def _print_query_help(self, url, cache=True):
10041004
result_string.append("{0} {1}: {2}"
10051005
.format(checkbox, name, value))
10061006

1007-
print("\n".join(result_string))
1007+
log.info("\n".join(result_string))
10081008
return result_string
10091009

10101010
def _print_surveys_help(self, url, cache=True):
@@ -1081,7 +1081,7 @@ def _print_surveys_help(self, url, cache=True):
10811081
if name.strip() in helptext_dict:
10821082
result_string.append(helptext_dict[name.strip()])
10831083

1084-
print("\n".join(result_string))
1084+
log.info("\n".join(result_string))
10851085
return result_string
10861086

10871087

astroquery/utils/tap/core.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ def load_table(self, table, verbose=False):
169169
"""
170170
if table is None:
171171
raise ValueError("Table name is required")
172-
print(f"Retrieving table '{table}'")
172+
if verbose:
173+
print(f"Retrieving table '{table}'")
173174
response = self.__connHandler.execute_tapget(f"tables?tables={table}",
174175
verbose=verbose)
175176
if verbose:
@@ -903,7 +904,7 @@ def load_groups(self, verbose=False):
903904
print("Parsing groups...")
904905
gsp = GroupSaxParser()
905906
gsp.parseData(response)
906-
print(f"Done. {len(gsp.get_groups())} groups found")
907+
log.info(f"Done. {len(gsp.get_groups())} groups found")
907908
if verbose:
908909
for g in gsp.get_groups():
909910
print(g.title)
@@ -958,7 +959,7 @@ def load_shared_items(self, verbose=False):
958959
print("Parsing shared items...")
959960
ssp = SharedItemsSaxParser()
960961
ssp.parseData(response)
961-
print(f"Done. {len(ssp.get_shared_items())} shared items found")
962+
log.info(f"Done. {len(ssp.get_shared_items())} shared items found")
962963
if verbose:
963964
for g in ssp.get_shared_items():
964965
print(g.title)
@@ -1007,7 +1008,7 @@ def share_table(self, group_name=None,
10071008
verbose,
10081009
200)
10091010
msg = f"Shared table '{table_name}' to group '{group_name}'."
1010-
print(msg)
1011+
log.info(msg)
10111012

10121013
def share_table_stop(self, group_name=None, table_name=None,
10131014
verbose=False):
@@ -1055,7 +1056,7 @@ def share_table_stop(self, group_name=None, table_name=None,
10551056
200)
10561057

10571058
msg = f"Stop sharing table '{table_name}' to group '{group_name}'."
1058-
print(msg)
1059+
log.info(msg)
10591060

10601061
def share_group_create(self, group_name=None, description=None,
10611062
verbose=False):
@@ -1090,7 +1091,7 @@ def share_group_create(self, group_name=None, description=None,
10901091
verbose,
10911092
200)
10921093
msg = f"Created group '{group_name}'."
1093-
print(msg)
1094+
log.info(msg)
10941095

10951096
def share_group_delete(self,
10961097
group_name=None,
@@ -1119,7 +1120,7 @@ def share_group_delete(self,
11191120
verbose,
11201121
200)
11211122
msg = f"Deleted group '{group_name}'."
1122-
print(msg)
1123+
log.info(msg)
11231124

11241125
def share_group_add_user(self,
11251126
group_name=None,
@@ -1169,7 +1170,7 @@ def share_group_add_user(self,
11691170
verbose,
11701171
200)
11711172
msg = f"Added user '{user_id}' from group '{group_name}'."
1172-
print(msg)
1173+
log.info(msg)
11731174

11741175
def share_group_delete_user(self,
11751176
group_name=None,
@@ -1220,7 +1221,7 @@ def share_group_delete_user(self,
12201221
verbose,
12211222
200)
12221223
msg = f"Deleted user '{user_id}' from group '{group_name}'."
1223-
print(msg)
1224+
log.info(msg)
12241225

12251226
def is_valid_user(self, user_id=None, verbose=False):
12261227
"""Determines if the specified user exists in the system
@@ -1367,7 +1368,7 @@ def remove_jobs(self, jobs_list, verbose=False):
13671368
verbose,
13681369
200)
13691370
msg = f"Removed jobs: '{jobs_list}'."
1370-
print(msg)
1371+
log.info(msg)
13711372

13721373
def __execLogin(self, usr, pwd, verbose=False):
13731374
subContext = "login"
@@ -1428,10 +1429,10 @@ def upload_table(self, upload_resource=None, table_name=None,
14281429
job.jobid = jobid
14291430
job.name = 'Table upload'
14301431
job.set_phase('EXECUTING')
1431-
print(f"Job '{jobid}' created to upload table '{table_name}'.")
1432+
log.info(f"Job '{jobid}' created to upload table '{table_name}'.")
14321433
return job
14331434
else:
1434-
print(f"Uploaded table '{table_name}'.")
1435+
log.info(f"Uploaded table '{table_name}'.")
14351436
return None
14361437

14371438
def __uploadTableMultipart(self, resource, table_name=None,
@@ -1445,7 +1446,7 @@ def __uploadTableMultipart(self, resource, table_name=None,
14451446
"TABLE_NAME": str(table_name),
14461447
"TABLE_DESC": str(table_description),
14471448
"FORMAT": 'votable'}
1448-
print("Sending pytable.")
1449+
log.info("Sending pytable.")
14491450
fh = tempfile.NamedTemporaryFile(delete=False)
14501451
resource.write(fh, format='votable')
14511452
fh.close()
@@ -1462,7 +1463,7 @@ def __uploadTableMultipart(self, resource, table_name=None,
14621463
"TABLE_NAME": str(table_name),
14631464
"TABLE_DESC": str(table_description),
14641465
"FORMAT": str(resource_format)}
1465-
print(f"Sending file: {resource}")
1466+
log.info(f"Sending file: {resource}")
14661467
with open(resource, "r") as f:
14671468
chunk = f.read()
14681469
files = [['FILE', os.path.basename(resource), chunk]]
@@ -1524,7 +1525,7 @@ def upload_table_from_job(self, job=None, table_name=None,
15241525
table_description=table_description,
15251526
verbose=verbose)
15261527
msg = f"Created table '{table_name}' from job: '{j.jobid}'."
1527-
print(msg)
1528+
log.info(msg)
15281529

15291530
def __uploadTableMultipartFromJob(self, resource, table_name=None,
15301531
table_description=None, verbose=False):
@@ -1581,7 +1582,7 @@ def delete_user_table(self, table_name=None, force_removal=False,
15811582
verbose,
15821583
200)
15831584
msg = f"Table '{table_name}' deleted."
1584-
print(msg)
1585+
log.info(msg)
15851586

15861587
def rename_table(self, table_name=None, new_table_name=None, new_column_names_dict=None,
15871588
verbose=False):
@@ -1742,7 +1743,7 @@ def update_user_table(self, table_name=None, list_of_changes=[],
17421743
verbose,
17431744
200)
17441745
msg = f"Table '{table_name}' updated."
1745-
print(msg)
1746+
log.info(msg)
17461747

17471748
@staticmethod
17481749
def get_table_update_arguments(table_name, columns, list_of_changes):
@@ -1993,7 +1994,7 @@ def __dologin(self, verbose=False):
19931994
if cookie is not None:
19941995
self.__isLoggedIn = True
19951996
connHandler.set_cookie(cookie)
1996-
print("OK")
1997+
log.info("OK")
19971998

19981999
def logout(self, verbose=False):
19992000
"""Performs a logout

astroquery/utils/tap/model/job.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from astroquery.utils.tap.model import modelutils
2121
from astroquery.utils.tap.xmlparser import utils
2222
from astroquery.utils.tap import taputils
23+
from astropy.logger import log
2324
import requests
2425

2526

@@ -274,7 +275,7 @@ def save_results(self, verbose=False):
274275
else:
275276
if not self.async_:
276277
# sync: cannot access server again
277-
print("No results to save")
278+
log.info("No results to save")
278279
else:
279280
# Async
280281
self.wait_for_job_end(verbose)
@@ -316,7 +317,7 @@ def wait_for_job_end(self, verbose=False):
316317
lphase = None
317318
# execute job if not running
318319
if self._phase == 'PENDING':
319-
print("Job in PENDING phase, sending phase=RUN request.")
320+
log.info("Job in PENDING phase, sending phase=RUN request.")
320321
try:
321322
self.start(verbose)
322323
except Exception as ex:

astroquery/utils/tests/test_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import astropy.units as u
1414
from astropy.table import Table
1515
import astropy.utils.data as aud
16+
from astropy.logger import log
1617

1718
from ...utils import chunk_read, chunk_report, class_or_instance, commons
1819
from ...utils.process_asyncs import async_to_sync_docstr, async_to_sync
@@ -25,10 +26,10 @@ class SimpleQueryClass:
2526
def query(self):
2627
""" docstring """
2728
if self is SimpleQueryClass:
28-
print("Calling query as class method")
29+
log.info("Calling query as class method")
2930
return "class"
3031
else:
31-
print("Calling query as instance method")
32+
log.info("Calling query as instance method")
3233
return "instance"
3334

3435

@@ -381,7 +382,7 @@ def close(self):
381382
self.file.close()
382383

383384
def monkey_urlopen(x, *args, **kwargs):
384-
print("Monkeyed URLopen")
385+
log.info("Monkeyed URLopen")
385386
return MockRemote(fitsfilepath, *args, **kwargs)
386387

387388
def monkey_builder(tlscontext=None):
@@ -392,7 +393,7 @@ def monkey_builder(tlscontext=None):
392393
def monkey_urlrequest(x, *args, **kwargs):
393394
# urlrequest allows passing headers; this will just return the URL
394395
# because we're ignoring headers during mocked actions
395-
print("Monkeyed URLrequest")
396+
log.info("Monkeyed URLrequest")
396397
return x
397398

398399
aud.urllib.request.Request = monkey_urlrequest

0 commit comments

Comments
 (0)