From 64c9d168c35a57220ddc97e391c66b10f517efd3 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Tue, 30 Nov 2021 00:05:11 +0100 Subject: [PATCH 1/8] storage: publications_with_status: Return a list[Publication]. --- mobilizon_reshare/storage/query/read.py | 7 ++----- tests/storage/test_query.py | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/mobilizon_reshare/storage/query/read.py b/mobilizon_reshare/storage/query/read.py index 67a9bf6..87baa20 100644 --- a/mobilizon_reshare/storage/query/read.py +++ b/mobilizon_reshare/storage/query/read.py @@ -93,7 +93,7 @@ async def publications_with_status( event_mobilizon_id: Optional[UUID] = None, from_date: Optional[Arrow] = None, to_date: Optional[Arrow] = None, -) -> dict[UUID, Publication]: +) -> Publication: query = Publication.filter(status=status) if event_mobilizon_id: @@ -103,10 +103,7 @@ async def publications_with_status( query = _add_date_window(query, "timestamp", from_date, to_date) - publications_list = ( - await query.prefetch_related("publisher").order_by("timestamp").distinct() - ) - return {pub.id: pub for pub in publications_list} + return await query.prefetch_related("publisher").order_by("timestamp").distinct() async def events_without_publications( diff --git a/tests/storage/test_query.py b/tests/storage/test_query.py index d42007c..dbbbf93 100644 --- a/tests/storage/test_query.py +++ b/tests/storage/test_query.py @@ -5,7 +5,6 @@ import arrow import pytest from mobilizon_reshare.event.event import MobilizonEvent, EventPublicationStatus -from mobilizon_reshare.models.event import Event from mobilizon_reshare.models.publication import PublicationStatus from mobilizon_reshare.storage.query.read import ( get_published_events, @@ -83,7 +82,7 @@ async def test_publications_with_status( to_date=to_date, ) - assert publications == {pub.id: pub for pub in expected_result} + assert publications == expected_result @pytest.mark.asyncio From 2966e90d9d2eac2f60d907dbed865f98459a3be0 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Tue, 30 Nov 2021 00:28:55 +0100 Subject: [PATCH 2/8] cli: cli: Add --version. --- mobilizon_reshare/cli/cli.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mobilizon_reshare/cli/cli.py b/mobilizon_reshare/cli/cli.py index c79d389..2c4c8b2 100644 --- a/mobilizon_reshare/cli/cli.py +++ b/mobilizon_reshare/cli/cli.py @@ -10,6 +10,7 @@ from mobilizon_reshare.cli.commands.format.format import format_event from mobilizon_reshare.cli.commands.inspect.inspect_event import inspect_events from mobilizon_reshare.cli.commands.start.main import main as start_main from mobilizon_reshare.cli.commands.recap.main import main as recap_main +from mobilizon_reshare.config.config import current_version from mobilizon_reshare.config.publishers import publisher_names from mobilizon_reshare.event.event import EventPublicationStatus @@ -42,6 +43,13 @@ to_date_option = click.option( ) +def print_version(ctx, param, value): + if not value or ctx.resilient_parsing: + return + click.echo(current_version()) + ctx.exit() + + class InspectTarget(Enum): ALL = "all" WAITING = "waiting" @@ -51,6 +59,9 @@ class InspectTarget(Enum): @click.group() +@click.option( + "--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True +) def mobilizon_reshare(): pass From 2d8855f6fe8f3fe1737ed8b4f827e9a32a66c52d Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Tue, 30 Nov 2021 23:46:07 +0100 Subject: [PATCH 3/8] cli: inspect_event: Separate paged fields with \t. --- mobilizon_reshare/cli/commands/inspect/inspect_event.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mobilizon_reshare/cli/commands/inspect/inspect_event.py b/mobilizon_reshare/cli/commands/inspect/inspect_event.py index 2997888..838b760 100644 --- a/mobilizon_reshare/cli/commands/inspect/inspect_event.py +++ b/mobilizon_reshare/cli/commands/inspect/inspect_event.py @@ -27,8 +27,8 @@ def show_events(events: Iterable[MobilizonEvent]): def pretty(event: MobilizonEvent): return ( - f"{event.name}|{click.style(event.status.name, fg=status_to_color[event.status])}" - f"|{event.mobilizon_id}|{event.begin_datetime.isoformat()}->{event.end_datetime.isoformat()}" + f"{event.name}\t{click.style(event.status.name, fg=status_to_color[event.status])}" + f"\t{event.mobilizon_id}\t{event.begin_datetime.isoformat()}->{event.end_datetime.isoformat()}" ) From 6f8f96d5b671f6b4f193b4bc203a9f1580075111 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Wed, 1 Dec 2021 01:08:37 +0100 Subject: [PATCH 4/8] cli: inspect: Refactor command. Now the inspect command can display informations about different kind of objects including events and publications. This patch also changes the cli to output columnar values suitable for further processing with standard Unix tool, such as awk. $ mobilizon-reshare.sh inspect publication -s completed | awk '{ print }' | sort | uniq -c [2021-12-01 01:05:55,321] [20] [INFO] Tortoise-ORM shutdown 2 mastodon 2 telegram 2 zulip --- mobilizon_reshare/cli/cli.py | 53 +++++++++++-------- .../cli/commands/inspect/inspect_event.py | 4 +- .../commands/inspect/inspect_publication.py | 41 ++++++++++++++ mobilizon_reshare/models/publication.py | 4 +- mobilizon_reshare/storage/query/read.py | 24 +++++++-- tests/publishers/test_coordinator.py | 4 +- 6 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 mobilizon_reshare/cli/commands/inspect/inspect_publication.py diff --git a/mobilizon_reshare/cli/cli.py b/mobilizon_reshare/cli/cli.py index 2c4c8b2..5deac7e 100644 --- a/mobilizon_reshare/cli/cli.py +++ b/mobilizon_reshare/cli/cli.py @@ -1,26 +1,35 @@ import functools -from enum import Enum import click from arrow import Arrow -from click import pass_context from mobilizon_reshare.cli import safe_execution from mobilizon_reshare.cli.commands.format.format import format_event from mobilizon_reshare.cli.commands.inspect.inspect_event import inspect_events +from mobilizon_reshare.cli.commands.inspect.inspect_publication import ( + inspect_publications, +) from mobilizon_reshare.cli.commands.start.main import main as start_main from mobilizon_reshare.cli.commands.recap.main import main as recap_main from mobilizon_reshare.config.config import current_version from mobilizon_reshare.config.publishers import publisher_names from mobilizon_reshare.event.event import EventPublicationStatus +from mobilizon_reshare.models.publication import PublicationStatus status_name_to_enum = { - "waiting": EventPublicationStatus.WAITING, - "completed": EventPublicationStatus.COMPLETED, - "failed": EventPublicationStatus.FAILED, - "partial": EventPublicationStatus.PARTIAL, - "all": None, + "event": { + "waiting": EventPublicationStatus.WAITING, + "completed": EventPublicationStatus.COMPLETED, + "failed": EventPublicationStatus.FAILED, + "partial": EventPublicationStatus.PARTIAL, + "all": None, + }, + "publication": { + "completed": PublicationStatus.COMPLETED, + "failed": PublicationStatus.FAILED, + "all": None, + }, } settings_file_option = click.option( @@ -41,6 +50,13 @@ to_date_option = click.option( expose_value=True, help="Include only events that begin before this datetime", ) +status_option = click.option( + "-s", + "--status", + default="all", + expose_value=True, + help="Include only objects with the given status", +) def print_version(ctx, param, value): @@ -50,14 +66,6 @@ def print_version(ctx, param, value): ctx.exit() -class InspectTarget(Enum): - ALL = "all" - WAITING = "waiting" - - def __str__(self): - return self.value - - @click.group() @click.option( "--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True @@ -78,22 +86,25 @@ def recap(settings_file): safe_execution(recap_main, settings_file=settings_file) -@mobilizon_reshare.command(help="Print events in the database that are in STATUS") +@mobilizon_reshare.command(help="List objects in the database with different criteria") @from_date_option @to_date_option @click.argument( - "status", type=click.Choice(list(status_name_to_enum.keys())), + "object", + type=click.Choice(list(status_name_to_enum.keys())), ) @settings_file_option -@pass_context -def inspect(ctx, status, begin, end, settings_file): - ctx.ensure_object(dict) +@status_option +def inspect(object, begin, end, settings_file, status): begin = Arrow.fromdatetime(begin) if begin else None end = Arrow.fromdatetime(end) if end else None safe_execution( functools.partial( - inspect_events, status_name_to_enum[status], frm=begin, to=end, + inspect_events if object == "event" else inspect_publications, + status_name_to_enum[object][status], + frm=begin, + to=end, ), settings_file, ) diff --git a/mobilizon_reshare/cli/commands/inspect/inspect_event.py b/mobilizon_reshare/cli/commands/inspect/inspect_event.py index 838b760..43b0643 100644 --- a/mobilizon_reshare/cli/commands/inspect/inspect_event.py +++ b/mobilizon_reshare/cli/commands/inspect/inspect_event.py @@ -27,8 +27,8 @@ def show_events(events: Iterable[MobilizonEvent]): def pretty(event: MobilizonEvent): return ( - f"{event.name}\t{click.style(event.status.name, fg=status_to_color[event.status])}" - f"\t{event.mobilizon_id}\t{event.begin_datetime.isoformat()}->{event.end_datetime.isoformat()}" + f"{event.name : ^40}{click.style(event.status.name, fg=status_to_color[event.status]) : ^22}" + f"{str(event.mobilizon_id) : <40}{event.begin_datetime.isoformat() : <29}{event.end_datetime.isoformat()}" ) diff --git a/mobilizon_reshare/cli/commands/inspect/inspect_publication.py b/mobilizon_reshare/cli/commands/inspect/inspect_publication.py new file mode 100644 index 0000000..4a77770 --- /dev/null +++ b/mobilizon_reshare/cli/commands/inspect/inspect_publication.py @@ -0,0 +1,41 @@ +from typing import Iterable + +import click +from arrow import Arrow + +from mobilizon_reshare.models.publication import Publication, PublicationStatus +from mobilizon_reshare.storage.query.read import ( + get_all_publications, + publications_with_status, +) + +status_to_color = { + PublicationStatus.COMPLETED: "green", + PublicationStatus.FAILED: "red", +} + + +def show_publications(publications: Iterable[Publication]): + click.echo_via_pager("\n".join(map(pretty, publications))) + + +def pretty(publication: Publication): + return ( + f"{str(publication.id) : <40}{publication.timestamp.isoformat() : <36}" + f"{click.style(publication.status.name, fg=status_to_color[publication.status]) : <22}" + f"{publication.publisher.name : <12}{str(publication.event.id)}" + ) + + +async def inspect_publications( + status: PublicationStatus = None, frm: Arrow = None, to: Arrow = None +): + if status is None: + publications = await get_all_publications(from_date=frm, to_date=to) + else: + publications = await publications_with_status(status, from_date=frm, to_date=to) + + if publications: + show_publications(list(publications)) + else: + click.echo(f"No publication found with status: {status}") diff --git a/mobilizon_reshare/models/publication.py b/mobilizon_reshare/models/publication.py index 927146e..bf954ec 100644 --- a/mobilizon_reshare/models/publication.py +++ b/mobilizon_reshare/models/publication.py @@ -13,9 +13,7 @@ class Publication(Model): id = fields.UUIDField(pk=True) status = fields.IntEnumField(PublicationStatus) - # When a Publication's status is WAITING - # we don't need a timestamp nor a reason - timestamp = fields.DatetimeField(null=True) + timestamp = fields.DatetimeField() reason = fields.TextField(null=True) event = fields.ForeignKeyField("models.Event", related_name="publications") diff --git a/mobilizon_reshare/storage/query/read.py b/mobilizon_reshare/storage/query/read.py index 87baa20..2991d60 100644 --- a/mobilizon_reshare/storage/query/read.py +++ b/mobilizon_reshare/storage/query/read.py @@ -55,6 +55,14 @@ async def events_with_status( ) +async def get_all_publications( + from_date: Optional[Arrow] = None, to_date: Optional[Arrow] = None, +) -> Iterable[Publication]: + return await prefetch_publication_relations( + _add_date_window(Publication.all(), "timestamp", from_date, to_date) + ) + + async def get_all_events( from_date: Optional[Arrow] = None, to_date: Optional[Arrow] = None, ) -> Iterable[MobilizonEvent]: @@ -74,6 +82,14 @@ async def prefetch_event_relations(queryset: QuerySet[Event]) -> list[Event]: ) +async def prefetch_publication_relations(queryset: QuerySet[Publication]) -> list[Publication]: + return ( + await queryset.prefetch_related("publisher", "event") + .order_by("timestamp") + .distinct() + ) + + def _add_date_window( query, field_name: str, @@ -93,7 +109,7 @@ async def publications_with_status( event_mobilizon_id: Optional[UUID] = None, from_date: Optional[Arrow] = None, to_date: Optional[Arrow] = None, -) -> Publication: +) -> Iterable[Publication]: query = Publication.filter(status=status) if event_mobilizon_id: @@ -101,9 +117,9 @@ async def publications_with_status( event__mobilizon_id=event_mobilizon_id ) - query = _add_date_window(query, "timestamp", from_date, to_date) - - return await query.prefetch_related("publisher").order_by("timestamp").distinct() + return await prefetch_publication_relations( + _add_date_window(query, "timestamp", from_date, to_date) + ) async def events_without_publications( diff --git a/tests/publishers/test_coordinator.py b/tests/publishers/test_coordinator.py index ceaf1ae..cb59e50 100644 --- a/tests/publishers/test_coordinator.py +++ b/tests/publishers/test_coordinator.py @@ -1,4 +1,5 @@ import logging +from datetime import timedelta from uuid import UUID import pytest @@ -18,6 +19,7 @@ from mobilizon_reshare.publishers.coordinator import ( PublicationFailureNotifiersCoordinator, RecapCoordinator, ) +from tests import today @pytest.fixture() @@ -91,7 +93,7 @@ async def mock_publications( id=UUID(int=i + 1), event=event, publisher=publisher, - timestamp=None, + timestamp=today + timedelta(hours=i), reason=None, ) publication = EventPublication.from_orm(publication, test_event) From 65ed0922049af1e6da92247df4793f0a2847279c Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Fri, 3 Dec 2021 00:04:36 +0100 Subject: [PATCH 5/8] cli: cli: Add option shortcuts. --- mobilizon_reshare/cli/cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mobilizon_reshare/cli/cli.py b/mobilizon_reshare/cli/cli.py index 5deac7e..7d7e514 100644 --- a/mobilizon_reshare/cli/cli.py +++ b/mobilizon_reshare/cli/cli.py @@ -33,18 +33,21 @@ status_name_to_enum = { } settings_file_option = click.option( + "-f", "--settings-file", type=click.Path(exists=True), help="The path for the settings file. " "Overrides the one specified in the environment variables.", ) from_date_option = click.option( + "-b", "--begin", type=click.DateTime(), expose_value=True, help="Include only events that begin after this datetime", ) to_date_option = click.option( + "-e", "--end", type=click.DateTime(), expose_value=True, From 833a3908397895cc65589954d347d8844badc923 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Fri, 3 Dec 2021 00:06:51 +0100 Subject: [PATCH 6/8] cli: inspect: Make two subcommands for events and publications. --- mobilizon_reshare/cli/cli.py | 88 ++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/mobilizon_reshare/cli/cli.py b/mobilizon_reshare/cli/cli.py index 7d7e514..f3096e8 100644 --- a/mobilizon_reshare/cli/cli.py +++ b/mobilizon_reshare/cli/cli.py @@ -2,6 +2,7 @@ import functools import click from arrow import Arrow +from click import pass_context from mobilizon_reshare.cli import safe_execution from mobilizon_reshare.cli.commands.format.format import format_event @@ -53,12 +54,21 @@ to_date_option = click.option( expose_value=True, help="Include only events that begin before this datetime", ) -status_option = click.option( +event_status_option = click.option( "-s", "--status", + type=click.Choice(list(status_name_to_enum["event"].keys())), default="all", expose_value=True, - help="Include only objects with the given status", + help="Include only events with the given status", +) +publication_status_option = click.option( + "-s", + "--status", + type=click.Choice(list(status_name_to_enum["publication"].keys())), + default="all", + expose_value=True, + help="Include only publications with the given status", ) @@ -73,43 +83,64 @@ def print_version(ctx, param, value): @click.option( "--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True ) -def mobilizon_reshare(): - pass +@settings_file_option +@pass_context +def mobilizon_reshare(ctx, settings_file): + ctx.ensure_object(dict) + ctx.obj["settings-file"] = settings_file @mobilizon_reshare.command(help="Synchronize and publish events") -@settings_file_option -def start(settings_file): - safe_execution(start_main, settings_file=settings_file) +def start(ctx): + ctx.ensure_object(dict) + safe_execution(start_main, settings_file=ctx.obj["settings-file"]) @mobilizon_reshare.command(help="Publish a recap of already published events") -@settings_file_option -def recap(settings_file): - safe_execution(recap_main, settings_file=settings_file) +def recap(ctx): + ctx.ensure_object(dict) + safe_execution(recap_main, settings_file=ctx.obj["settings-file"]) -@mobilizon_reshare.command(help="List objects in the database with different criteria") +@mobilizon_reshare.group(help="List objects in the database with different criteria") @from_date_option @to_date_option -@click.argument( - "object", - type=click.Choice(list(status_name_to_enum.keys())), -) -@settings_file_option -@status_option -def inspect(object, begin, end, settings_file, status): - begin = Arrow.fromdatetime(begin) if begin else None - end = Arrow.fromdatetime(end) if end else None +@pass_context +def inspect(ctx, begin, end): + ctx.ensure_object(dict) + ctx.obj["begin"] = Arrow.fromdatetime(begin) if begin else None + ctx.obj["end"] = Arrow.fromdatetime(end) if end else None + +@inspect.command(help="Query for events in the database") +@event_status_option +@pass_context +def event(ctx, status): + ctx.ensure_object(dict) safe_execution( functools.partial( - inspect_events if object == "event" else inspect_publications, - status_name_to_enum[object][status], - frm=begin, - to=end, + inspect_events, + status_name_to_enum["event"][status], + frm=ctx.obj["begin"], + to=ctx.obj["end"], ), - settings_file, + ctx.obj["settings-file"], + ) + + +@inspect.command(help="Query for publications in the database") +@publication_status_option +@pass_context +def publication(ctx, status): + ctx.ensure_object(dict) + safe_execution( + functools.partial( + inspect_publications, + status_name_to_enum["publication"][status], + frm=ctx.obj["begin"], + to=ctx.obj["end"], + ), + ctx.obj["settings-file"], ) @@ -120,11 +151,12 @@ def inspect(object, begin, end, settings_file, status): @settings_file_option @click.argument("event-id", type=click.UUID) @click.argument("publisher", type=click.Choice(publisher_names)) -def format(settings_file, event_id, publisher): +def format(ctx, event_id, publisher): + ctx.ensure_object(dict) safe_execution( - functools.partial(format_event, event_id, publisher), settings_file, + functools.partial(format_event, event_id, publisher), ctx.obj["settings-file"], ) if __name__ == "__main__": - mobilizon_reshare() + mobilizon_reshare(obj={}) From c07c0ad30dd5c332638a373bfbfa87757afa7ce2 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Sat, 4 Dec 2021 01:20:34 +0100 Subject: [PATCH 7/8] cli: cli: Add some consistency to help messages. --- mobilizon_reshare/cli/cli.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mobilizon_reshare/cli/cli.py b/mobilizon_reshare/cli/cli.py index f3096e8..bb4c3fc 100644 --- a/mobilizon_reshare/cli/cli.py +++ b/mobilizon_reshare/cli/cli.py @@ -45,14 +45,14 @@ from_date_option = click.option( "--begin", type=click.DateTime(), expose_value=True, - help="Include only events that begin after this datetime", + help="Include only events that begin after this datetime.", ) to_date_option = click.option( "-e", "--end", type=click.DateTime(), expose_value=True, - help="Include only events that begin before this datetime", + help="Include only events that begin before this datetime.", ) event_status_option = click.option( "-s", @@ -60,7 +60,7 @@ event_status_option = click.option( type=click.Choice(list(status_name_to_enum["event"].keys())), default="all", expose_value=True, - help="Include only events with the given status", + help="Include only events with the given STATUS.", ) publication_status_option = click.option( "-s", @@ -68,7 +68,7 @@ publication_status_option = click.option( type=click.Choice(list(status_name_to_enum["publication"].keys())), default="all", expose_value=True, - help="Include only publications with the given status", + help="Include only publications with the given STATUS.", ) @@ -90,19 +90,19 @@ def mobilizon_reshare(ctx, settings_file): ctx.obj["settings-file"] = settings_file -@mobilizon_reshare.command(help="Synchronize and publish events") +@mobilizon_reshare.command(help="Synchronize and publish events.") def start(ctx): ctx.ensure_object(dict) safe_execution(start_main, settings_file=ctx.obj["settings-file"]) -@mobilizon_reshare.command(help="Publish a recap of already published events") +@mobilizon_reshare.command(help="Publish a recap of already published events.") def recap(ctx): ctx.ensure_object(dict) safe_execution(recap_main, settings_file=ctx.obj["settings-file"]) -@mobilizon_reshare.group(help="List objects in the database with different criteria") +@mobilizon_reshare.group(help="List objects in the database with different criteria.") @from_date_option @to_date_option @pass_context @@ -112,7 +112,7 @@ def inspect(ctx, begin, end): ctx.obj["end"] = Arrow.fromdatetime(end) if end else None -@inspect.command(help="Query for events in the database") +@inspect.command(help="Query for events in the database.") @event_status_option @pass_context def event(ctx, status): @@ -128,7 +128,7 @@ def event(ctx, status): ) -@inspect.command(help="Query for publications in the database") +@inspect.command(help="Query for publications in the database.") @publication_status_option @pass_context def publication(ctx, status): @@ -145,8 +145,8 @@ def publication(ctx, status): @mobilizon_reshare.command( - help="Format and print event with mobilizon id EVENT-ID using the publisher's format named" - "PUBLISHER" + help="Format and print event with EVENT-ID using the publisher's format named " + "PUBLISHER." ) @settings_file_option @click.argument("event-id", type=click.UUID) From a5737d91a854eb94a1925dbfd8db58c498b0b802 Mon Sep 17 00:00:00 2001 From: Giacomo Leidi Date: Wed, 8 Dec 2021 13:32:45 +0100 Subject: [PATCH 8/8] cli: Move settings option to subcommands. --- mobilizon_reshare/cli/cli.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mobilizon_reshare/cli/cli.py b/mobilizon_reshare/cli/cli.py index bb4c3fc..5db5437 100644 --- a/mobilizon_reshare/cli/cli.py +++ b/mobilizon_reshare/cli/cli.py @@ -83,23 +83,22 @@ def print_version(ctx, param, value): @click.option( "--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True ) -@settings_file_option @pass_context -def mobilizon_reshare(ctx, settings_file): - ctx.ensure_object(dict) - ctx.obj["settings-file"] = settings_file +def mobilizon_reshare(): + pass @mobilizon_reshare.command(help="Synchronize and publish events.") -def start(ctx): +@settings_file_option +def start(ctx, settings): ctx.ensure_object(dict) - safe_execution(start_main, settings_file=ctx.obj["settings-file"]) + safe_execution(start_main, settings_file=settings) @mobilizon_reshare.command(help="Publish a recap of already published events.") -def recap(ctx): - ctx.ensure_object(dict) - safe_execution(recap_main, settings_file=ctx.obj["settings-file"]) +@settings_file_option +def recap(settings): + safe_execution(recap_main, settings_file=settings) @mobilizon_reshare.group(help="List objects in the database with different criteria.") @@ -114,8 +113,9 @@ def inspect(ctx, begin, end): @inspect.command(help="Query for events in the database.") @event_status_option +@settings_file_option @pass_context -def event(ctx, status): +def event(ctx, status, settings): ctx.ensure_object(dict) safe_execution( functools.partial( @@ -124,14 +124,15 @@ def event(ctx, status): frm=ctx.obj["begin"], to=ctx.obj["end"], ), - ctx.obj["settings-file"], + settings, ) @inspect.command(help="Query for publications in the database.") @publication_status_option +@settings_file_option @pass_context -def publication(ctx, status): +def publication(ctx, status, settings): ctx.ensure_object(dict) safe_execution( functools.partial( @@ -140,7 +141,7 @@ def publication(ctx, status): frm=ctx.obj["begin"], to=ctx.obj["end"], ), - ctx.obj["settings-file"], + settings, ) @@ -148,13 +149,12 @@ def publication(ctx, status): help="Format and print event with EVENT-ID using the publisher's format named " "PUBLISHER." ) -@settings_file_option @click.argument("event-id", type=click.UUID) @click.argument("publisher", type=click.Choice(publisher_names)) -def format(ctx, event_id, publisher): - ctx.ensure_object(dict) +@settings_file_option +def format(event_id, publisher, settings): safe_execution( - functools.partial(format_event, event_id, publisher), ctx.obj["settings-file"], + functools.partial(format_event, event_id, publisher), settings, )