removed settings_file cli option

This commit is contained in:
Simone Robutti 2021-12-29 17:14:42 +01:00
parent 993fc60e14
commit ce4b54384f
4 changed files with 25 additions and 39 deletions

View File

@ -3,7 +3,6 @@ import logging
import traceback
from logging.config import dictConfig
from pathlib import Path
import sys
from mobilizon_reshare.config.config import get_settings
from mobilizon_reshare.storage.db import tear_down, MoReDB
@ -16,23 +15,21 @@ async def graceful_exit(code):
exit(code)
async def init(settings_file):
settings = get_settings(settings_file)
async def init():
settings = get_settings()
dictConfig(settings["logging"])
db_path = Path(settings.db_path)
db = MoReDB(db_path)
db_setup = asyncio.create_task(db.setup())
_, _ = await asyncio.wait({db_setup},
return_when=asyncio.FIRST_EXCEPTION)
_, _ = await asyncio.wait({db_setup}, return_when=asyncio.FIRST_EXCEPTION)
if db_setup.exception():
logging.critical("exception during db setup")
raise db_setup.exception()
async def _safe_execution(f, settings_file):
init_task = asyncio.create_task(init(settings_file))
_, _ = await asyncio.wait({init_task},
return_when=asyncio.FIRST_EXCEPTION)
async def _safe_execution(f):
init_task = asyncio.create_task(init())
_, _ = await asyncio.wait({init_task}, return_when=asyncio.FIRST_EXCEPTION)
if init_task.exception():
logging.critical("exception during init")
# raise init_task.exception()
@ -50,5 +47,5 @@ async def _safe_execution(f, settings_file):
await graceful_exit(return_code)
def safe_execution(f, settings_file):
asyncio.run(_safe_execution(f, settings_file))
def safe_execution(f):
asyncio.run(_safe_execution(f))

View File

@ -10,11 +10,10 @@ 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.cli.commands.start.main import main as start_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
@ -32,14 +31,6 @@ status_name_to_enum = {
"all": None,
},
}
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",
@ -89,17 +80,15 @@ def mobilizon_reshare(obj):
@mobilizon_reshare.command(help="Synchronize and publish events.")
@settings_file_option
@pass_context
def start(ctx, settings_file):
def start(ctx,):
ctx.ensure_object(dict)
safe_execution(start_main, settings_file=settings_file)
safe_execution(start_main,)
@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():
safe_execution(recap_main,)
@mobilizon_reshare.group(help="List objects in the database with different criteria.")
@ -114,9 +103,10 @@ 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, settings_file):
def event(
ctx, status,
):
ctx.ensure_object(dict)
safe_execution(
functools.partial(
@ -125,15 +115,15 @@ def event(ctx, status, settings_file):
frm=ctx.obj["begin"],
to=ctx.obj["end"],
),
settings_file,
)
@inspect.command(help="Query for publications in the database.")
@publication_status_option
@settings_file_option
@pass_context
def publication(ctx, status, settings_file):
def publication(
ctx, status,
):
ctx.ensure_object(dict)
safe_execution(
functools.partial(
@ -142,7 +132,6 @@ def publication(ctx, status, settings_file):
frm=ctx.obj["begin"],
to=ctx.obj["end"],
),
settings_file,
)
@ -152,11 +141,10 @@ def publication(ctx, status, settings_file):
)
@click.argument("event-id", type=click.UUID)
@click.argument("publisher", type=click.Choice(publisher_names))
@settings_file_option
def format(event_id, publisher, settings_file):
safe_execution(
functools.partial(format_event, event_id, publisher), settings_file,
)
def format(
event_id, publisher,
):
safe_execution(functools.partial(format_event, event_id, publisher),)
if __name__ == "__main__":

View File

@ -41,6 +41,7 @@ class TelegramFormatter(AbstractEventFormatter):
")",
">",
"<",
">",
"{",
"}",
]

View File

@ -4,7 +4,7 @@ group="my_group"
[testing.selection]
strategy = "next_event"
9
[testing.selection.strategy_options]
break_between_events_in_minutes =60