2021-08-04 18:53:58 +02:00
|
|
|
import functools
|
|
|
|
|
|
|
|
import click
|
2021-12-03 00:06:51 +01:00
|
|
|
from click import pass_context
|
2021-08-04 18:53:58 +02:00
|
|
|
|
2021-08-16 10:49:52 +02:00
|
|
|
from mobilizon_reshare.cli import safe_execution
|
2021-10-25 13:43:38 +02:00
|
|
|
from mobilizon_reshare.cli.commands.format.format import format_event
|
2022-02-14 21:10:27 +01:00
|
|
|
from mobilizon_reshare.cli.commands.list.list_event import list_events
|
|
|
|
from mobilizon_reshare.cli.commands.list.list_publication import list_publications
|
2022-03-02 08:59:57 +01:00
|
|
|
from mobilizon_reshare.cli.commands.recap.main import recap_command as recap_main
|
|
|
|
from mobilizon_reshare.cli.commands.start.main import start_command as start_main
|
2022-03-22 21:16:34 +01:00
|
|
|
from mobilizon_reshare.cli.commands.pull.main import pull_command as pull_main
|
|
|
|
from mobilizon_reshare.cli.commands.publish.main import publish_command as publish_main
|
2021-11-30 00:28:55 +01:00
|
|
|
from mobilizon_reshare.config.config import current_version
|
2021-10-25 13:43:38 +02:00
|
|
|
from mobilizon_reshare.config.publishers import publisher_names
|
2021-08-16 10:49:52 +02:00
|
|
|
from mobilizon_reshare.event.event import EventPublicationStatus
|
2022-03-02 08:59:57 +01:00
|
|
|
from mobilizon_reshare.cli.commands.retry.main import (
|
|
|
|
retry_event_command,
|
|
|
|
retry_publication_command,
|
|
|
|
)
|
2021-12-01 01:08:37 +01:00
|
|
|
from mobilizon_reshare.models.publication import PublicationStatus
|
2021-08-04 18:53:58 +02:00
|
|
|
|
2021-10-25 13:43:38 +02:00
|
|
|
status_name_to_enum = {
|
2021-12-01 01:08:37 +01:00
|
|
|
"event": {
|
|
|
|
"waiting": EventPublicationStatus.WAITING,
|
|
|
|
"completed": EventPublicationStatus.COMPLETED,
|
|
|
|
"failed": EventPublicationStatus.FAILED,
|
|
|
|
"partial": EventPublicationStatus.PARTIAL,
|
|
|
|
"all": None,
|
|
|
|
},
|
|
|
|
"publication": {
|
|
|
|
"completed": PublicationStatus.COMPLETED,
|
|
|
|
"failed": PublicationStatus.FAILED,
|
|
|
|
"all": None,
|
|
|
|
},
|
2021-10-25 13:43:38 +02:00
|
|
|
}
|
2021-08-14 18:23:55 +02:00
|
|
|
from_date_option = click.option(
|
2021-12-03 00:04:36 +01:00
|
|
|
"-b",
|
2021-08-14 18:23:55 +02:00
|
|
|
"--begin",
|
|
|
|
type=click.DateTime(),
|
|
|
|
expose_value=True,
|
2021-12-04 01:20:34 +01:00
|
|
|
help="Include only events that begin after this datetime.",
|
2021-08-14 18:23:55 +02:00
|
|
|
)
|
|
|
|
to_date_option = click.option(
|
2021-12-03 00:04:36 +01:00
|
|
|
"-e",
|
2021-08-14 18:23:55 +02:00
|
|
|
"--end",
|
|
|
|
type=click.DateTime(),
|
|
|
|
expose_value=True,
|
2021-12-04 01:20:34 +01:00
|
|
|
help="Include only events that begin before this datetime.",
|
2021-08-14 18:23:55 +02:00
|
|
|
)
|
2022-02-14 21:10:27 +01:00
|
|
|
event_status_option = click.argument(
|
|
|
|
"status",
|
2021-12-03 00:06:51 +01:00
|
|
|
type=click.Choice(list(status_name_to_enum["event"].keys())),
|
2021-12-01 01:08:37 +01:00
|
|
|
default="all",
|
|
|
|
expose_value=True,
|
2021-12-03 00:06:51 +01:00
|
|
|
)
|
2022-02-14 21:10:27 +01:00
|
|
|
publication_status_option = click.argument(
|
|
|
|
"status",
|
2021-12-03 00:06:51 +01:00
|
|
|
type=click.Choice(list(status_name_to_enum["publication"].keys())),
|
|
|
|
default="all",
|
|
|
|
expose_value=True,
|
2021-12-01 01:08:37 +01:00
|
|
|
)
|
2021-08-04 18:53:58 +02:00
|
|
|
|
|
|
|
|
2021-11-30 00:28:55 +01:00
|
|
|
def print_version(ctx, param, value):
|
|
|
|
if not value or ctx.resilient_parsing:
|
|
|
|
return
|
|
|
|
click.echo(current_version())
|
|
|
|
ctx.exit()
|
|
|
|
|
|
|
|
|
2021-08-04 18:53:58 +02:00
|
|
|
@click.group()
|
2021-11-30 00:28:55 +01:00
|
|
|
@click.option(
|
|
|
|
"--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True
|
|
|
|
)
|
2021-12-03 00:06:51 +01:00
|
|
|
@pass_context
|
2021-12-14 20:30:08 +01:00
|
|
|
def mobilizon_reshare(obj):
|
2021-12-08 13:32:45 +01:00
|
|
|
pass
|
2021-08-04 18:53:58 +02:00
|
|
|
|
|
|
|
|
2022-03-22 21:16:34 +01:00
|
|
|
@mobilizon_reshare.command(
|
|
|
|
help="Synchronize and publish events. It is equivalent to running consecutively pull and then publish."
|
|
|
|
)
|
2021-12-14 20:30:08 +01:00
|
|
|
@pass_context
|
2022-03-22 21:16:34 +01:00
|
|
|
def start(
|
|
|
|
ctx,
|
|
|
|
):
|
2021-12-03 00:06:51 +01:00
|
|
|
ctx.ensure_object(dict)
|
2022-03-22 21:16:34 +01:00
|
|
|
safe_execution(
|
|
|
|
start_main,
|
|
|
|
)
|
2021-10-16 01:25:45 +02:00
|
|
|
|
|
|
|
|
2021-12-04 01:20:34 +01:00
|
|
|
@mobilizon_reshare.command(help="Publish a recap of already published events.")
|
2022-01-08 00:54:27 +01:00
|
|
|
def recap():
|
2022-03-22 21:16:34 +01:00
|
|
|
safe_execution(
|
|
|
|
recap_main,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@mobilizon_reshare.command(
|
|
|
|
help="Fetch the latest events from Mobilizon and store them."
|
|
|
|
)
|
|
|
|
def pull():
|
|
|
|
safe_execution(
|
|
|
|
pull_main,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@mobilizon_reshare.command(help="Select an event and publish it.")
|
|
|
|
def publish():
|
|
|
|
safe_execution(
|
|
|
|
publish_main,
|
|
|
|
)
|
2021-08-04 18:53:58 +02:00
|
|
|
|
|
|
|
|
2022-02-14 21:10:27 +01:00
|
|
|
@mobilizon_reshare.group(help="Operations that pertain to events")
|
|
|
|
def event():
|
|
|
|
pass
|
2021-12-03 00:06:51 +01:00
|
|
|
|
|
|
|
|
2022-02-14 21:10:27 +01:00
|
|
|
@mobilizon_reshare.group(help="Operations that pertain to publications")
|
|
|
|
def publication():
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@event.command(help="Query for events in the database.", name="list")
|
2021-12-03 00:06:51 +01:00
|
|
|
@event_status_option
|
2022-02-14 21:10:27 +01:00
|
|
|
@from_date_option
|
|
|
|
@to_date_option
|
|
|
|
def event_list(status, begin, end):
|
|
|
|
|
2021-12-03 00:06:51 +01:00
|
|
|
safe_execution(
|
|
|
|
functools.partial(
|
2022-03-22 21:16:34 +01:00
|
|
|
list_events,
|
|
|
|
status_name_to_enum["event"][status],
|
|
|
|
frm=begin,
|
|
|
|
to=end,
|
2021-12-03 00:06:51 +01:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2021-10-25 13:43:38 +02:00
|
|
|
|
2022-02-14 21:10:27 +01:00
|
|
|
@publication.command(help="Query for publications in the database.", name="list")
|
2021-12-03 00:06:51 +01:00
|
|
|
@publication_status_option
|
2022-02-14 21:10:27 +01:00
|
|
|
@from_date_option
|
|
|
|
@to_date_option
|
|
|
|
def publication_list(status, begin, end):
|
2021-08-04 18:53:58 +02:00
|
|
|
safe_execution(
|
2021-10-25 13:43:38 +02:00
|
|
|
functools.partial(
|
2022-02-14 21:10:27 +01:00
|
|
|
list_publications,
|
2021-12-03 00:06:51 +01:00
|
|
|
status_name_to_enum["publication"][status],
|
2022-02-14 21:10:27 +01:00
|
|
|
frm=begin,
|
|
|
|
to=end,
|
2021-10-25 13:43:38 +02:00
|
|
|
),
|
2021-08-04 18:53:58 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-02-14 21:10:27 +01:00
|
|
|
@event.command(
|
2021-12-04 01:20:34 +01:00
|
|
|
help="Format and print event with EVENT-ID using the publisher's format named "
|
|
|
|
"PUBLISHER."
|
2021-10-25 13:43:38 +02:00
|
|
|
)
|
|
|
|
@click.argument("event-id", type=click.UUID)
|
|
|
|
@click.argument("publisher", type=click.Choice(publisher_names))
|
2022-01-08 00:54:27 +01:00
|
|
|
def format(
|
2022-03-22 21:16:34 +01:00
|
|
|
event_id,
|
|
|
|
publisher,
|
2022-01-08 00:54:27 +01:00
|
|
|
):
|
2022-03-22 21:16:34 +01:00
|
|
|
safe_execution(
|
|
|
|
functools.partial(format_event, event_id, publisher),
|
|
|
|
)
|
2021-08-04 18:53:58 +02:00
|
|
|
|
|
|
|
|
2022-02-14 21:10:27 +01:00
|
|
|
@event.command(name="retry", help="Retries all the failed publications")
|
|
|
|
@click.argument("event-id", type=click.UUID)
|
|
|
|
def event_retry(event_id):
|
2022-03-22 21:16:34 +01:00
|
|
|
safe_execution(
|
|
|
|
functools.partial(retry_event_command, event_id),
|
|
|
|
)
|
2022-02-14 21:10:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
@publication.command(name="retry", help="Retries a specific publication")
|
|
|
|
@click.argument("publication-id", type=click.UUID)
|
|
|
|
def publication_retry(publication_id):
|
2022-03-22 21:16:34 +01:00
|
|
|
safe_execution(
|
|
|
|
functools.partial(retry_publication_command, publication_id),
|
|
|
|
)
|
2022-02-14 21:10:27 +01:00
|
|
|
|
|
|
|
|
2021-08-04 18:53:58 +02:00
|
|
|
if __name__ == "__main__":
|
2021-12-03 00:06:51 +01:00
|
|
|
mobilizon_reshare(obj={})
|