Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyprint instead of print #43

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))