Skip to content

Commit

Permalink
feat: Add ERROR notes to collectionstatus. Color output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jun 3, 2024
1 parent 5d67982 commit 6826645
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions process/management/commands/collectionstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from process.cli import CollectionCommand
from process.management.commands.compiler import compilable
from process.management.commands.finisher import completable
from process.models import CollectionNote
from process.util import wrap as w


Expand All @@ -31,6 +32,11 @@ class Command(CollectionCommand):
def create_parser(self, prog_name, subcommand, **kwargs):
return super().create_parser(prog_name, subcommand, formatter_class=RawDescriptionHelpFormatter, **kwargs)

def bool_to_str(self, boolean):
if boolean:
return self.style.SUCCESS("yes")
return self.style.WARNING("no (or not yet)")

def handle_collection(self, collection, *args, **options):
if collection.parent_id:
raise CommandError(
Expand All @@ -46,7 +52,7 @@ def handle_collection(self, collection, *args, **options):
if collection.data_type["concatenated"]:
data_type = f"concatenated JSON, starting with {data_type}"
else:
data_type = "to be determined"
data_type = self.style.WARNING("to be determined")

# Fields
self.stdout.write(f"steps: {', '.join(collection.steps)}")
Expand All @@ -63,9 +69,20 @@ def handle_collection(self, collection, *args, **options):

# Logic
if not compiled_collection or not compiled_collection.compilation_started:
self.stdout.write(f"compilable: {compilable(collection)}")
self.stdout.write(f"compilable: {self.bool_to_str(compilable(collection))}")
if not collection.completed_at:
self.stdout.write(f"completable: {completable(collection)}")
self.stdout.write(f"completable: {self.bool_to_str(completable(collection))}")

# Notes
notes = (
collection.collectionnote_set.filter(code=CollectionNote.Level.ERROR)
.exclude(data__has_key="http_error") # Exclude "Couldn't download {url}"
.all()
)
if notes:
self.stdout.write(self.style.ERROR("Error-level collection notes:"))
for note in notes:
self.stdout.write(self.style.ERROR(f"- {note.note} ({note.data})"))

if compiled_collection:
self.stdout.write("\nCompiled collection")
Expand All @@ -81,4 +98,4 @@ def handle_collection(self, collection, *args, **options):

# Logic
if not compiled_collection.completed_at:
self.stdout.write(f"completable: {completable(compiled_collection)}")
self.stdout.write(f"completable: {self.bool_to_str(completable(compiled_collection))}")

0 comments on commit 6826645

Please sign in to comment.