Skip to content

Commit

Permalink
Use pyprint instead of print
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhwaniartefact authored Jun 13, 2024
1 parent cc737b0 commit fd80ed0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
21 changes: 8 additions & 13 deletions fixity/fixity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions fixity/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from datetime import datetime
from datetime import timezone
from uuid import UUID
Expand Down Expand Up @@ -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))

0 comments on commit fd80ed0

Please sign in to comment.