From fd80ed0c90517aaa438462ea55068a396ab0f01b Mon Sep 17 00:00:00 2001 From: Dhwani Patel Date: Thu, 13 Jun 2024 15:43:24 -0600 Subject: [PATCH] Use pyprint instead of print --- fixity/fixity.py | 21 ++++++++------------- fixity/utils.py | 5 +++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/fixity/fixity.py b/fixity/fixity.py index 067d1b3..85bc912 100644 --- a/fixity/fixity.py +++ b/fixity/fixity.py @@ -135,7 +135,7 @@ def scan( session_id=session_id, ) except reporting.ReportServiceException: - print(f"Unable to POST pre-scan report to {report_url}", file=sys.stderr) + utils.pyprint(f"Unable to POST pre-scan report to {report_url}") try: status, report = storage_service.scan_aip( @@ -148,9 +148,9 @@ def scan( force_local=force_local, ) report_data = json.loads(report.report) - print(scan_message(aip, status, report_data["message"]), file=sys.stderr) + utils.pyprint(scan_message(aip, status, report_data["message"])) except Exception as e: - print(str(e), file=sys.stderr) + utils.pyprint(str(e)) status = None if hasattr(e, "report") and e.report: report = e.report @@ -181,10 +181,7 @@ def scan( aip, report, report_url, report_auth=report_auth, session_id=session_id ) except reporting.ReportServiceException: - print( - f"Unable to POST report for AIP {aip} to remote service", - file=sys.stderr, - ) + utils.pyprint(f"Unable to POST report for AIP {aip} to remote service") if report: session.add(report) @@ -240,17 +237,15 @@ def scanall( if not scan_success: success = False except Exception as e: - print( - "Internal error encountered while scanning AIP {} ({})".format( - aip["uuid"], type(e).__name__ - ) + utils.pyprint( + f"Internal error encountered while scanning AIP {aip['uuid']} ({type(e).__name__})", + file=sys.stdout, ) - if throttle_time: sleep(throttle_time) if count > 0: - print("Successfully scanned", count, "AIPs", file=sys.stderr) + utils.pyprint(f"Successfully scanned {count} AIPs") return success diff --git a/fixity/utils.py b/fixity/utils.py index 9d8b8d1..9abe683 100644 --- a/fixity/utils.py +++ b/fixity/utils.py @@ -1,3 +1,4 @@ +import sys from datetime import datetime from datetime import timezone from uuid import UUID @@ -33,3 +34,7 @@ def check_valid_uuid(uuid): def utcnow(): return datetime.now(timezone.utc) + + +def pyprint(message, **kwargs): + print(message, file=kwargs.get("file", sys.stderr))