~homeworkprod/byceps

c8b4b0f58f33432fbeff3e25175677aa9cbb5c14 — Jochen Kupperschmidt 9 months ago d216b81
Introduce one-line helper for script execution
M scripts/_util.py => scripts/_util.py +7 -0
@@ 9,6 9,7 @@ Utilities for scripts
"""

from contextlib import contextmanager
from typing import Callable

from byceps.application import create_app



@@ 21,3 22,9 @@ def app_context():
    app = create_app()
    with app.app_context():
        yield app


def call_with_app_context(func: Callable) -> None:
    """Call a callable inside of an application context."""
    with app_context():
        func()

M scripts/add_archived_attendance.py => scripts/add_archived_attendance.py +2 -3
@@ 11,7 11,7 @@ import click
from byceps.services.ticketing import attendance_service
from byceps.services.user import service as user_service

from _util import app_context
from _util import call_with_app_context
from _validators import validate_party, validate_user_id




@@ 31,5 31,4 @@ def execute(user, party):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/announce_orga_birthdays.py => scripts/announce_orga_birthdays.py +2 -3
@@ 15,7 15,7 @@ from byceps.services.orga import birthday_service
from byceps.services.webhooks import service as webhook_service
from byceps.services.webhooks.transfer.models import OutgoingWebhook, WebhookID

from _util import app_context
from _util import call_with_app_context


def validate_webhook_id(ctx, param, webhook_id: WebhookID) -> OutgoingWebhook:


@@ 40,5 40,4 @@ def execute(webhook: OutgoingWebhook):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/clean_up_after_deleted_users.py => scripts/clean_up_after_deleted_users.py +2 -3
@@ 39,7 39,7 @@ from byceps.services.verification_token.dbmodels import (
)
from byceps.typing import UserID

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 171,5 171,4 @@ def _execute_delete_for_users_query(model, user_ids: Set[UserID]) -> int:


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/copy_snippets.py => scripts/copy_snippets.py +2 -3
@@ 11,7 11,7 @@ import click
from byceps.services.snippet import service as snippet_service
from byceps.services.snippet.transfer.models import Scope, SnippetType

from _util import app_context
from _util import call_with_app_context
from _validators import validate_site




@@ 91,5 91,4 @@ def scope_as_string(scope):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/create_database_tables.py => scripts/create_database_tables.py +2 -3
@@ 12,7 12,7 @@ import click

from byceps.database import db

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 25,5 25,4 @@ def execute():


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/create_initial_admin_user.py => scripts/create_initial_admin_user.py +2 -3
@@ 12,7 12,7 @@ from byceps.services.authorization import service as authorization_service
from byceps.services.user import command_service as user_command_service
from byceps.services.user import creation_service as user_creation_service

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 56,5 56,4 @@ def _assign_roles_to_user(roles, user_id):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/create_seating_area.py => scripts/create_seating_area.py +2 -3
@@ 10,7 10,7 @@ import click

from byceps.services.seating import area_service

from _util import app_context
from _util import call_with_app_context
from _validators import validate_party




@@ 24,5 24,4 @@ def execute(party, slug, title):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/create_terms_version.py => scripts/create_terms_version.py +2 -3
@@ 17,7 17,7 @@ from byceps.services.terms import document_service as terms_document_service
from byceps.services.terms.transfer.models import DocumentID
from byceps.services.terms import version_service as terms_version_service

from _util import app_context
from _util import call_with_app_context
from _validators import validate_brand




@@ 71,5 71,4 @@ def _create_consent_subject(brand, title, consent_subject_name_suffix):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/delete_old_user_login_events.py => scripts/delete_old_user_login_events.py +2 -3
@@ 12,7 12,7 @@ import click

from byceps.services.user import event_service as user_event_service

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 32,5 32,4 @@ def execute(minimum_age_in_days):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/export_permissions_and_roles.py => scripts/export_permissions_and_roles.py +2 -3
@@ 10,7 10,7 @@ import click

from byceps.services.authorization import impex_service

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 19,5 19,4 @@ def execute():


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/export_ticket_user_email_addresses.py => scripts/export_ticket_user_email_addresses.py +2 -3
@@ 14,7 14,7 @@ from byceps.services.ticketing import ticket_service
from byceps.services.user import service as user_service
from byceps.typing import PartyID

from _util import app_context
from _util import call_with_app_context
from _validators import validate_party




@@ 40,5 40,4 @@ def _get_email_addresses(party_id: PartyID) -> Iterator[str]:


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/find_logins_for_ipaddress.py => scripts/find_logins_for_ipaddress.py +2 -3
@@ 15,7 15,7 @@ from byceps.services.user import service as user_service
from byceps.services.user.transfer.models import User
from byceps.typing import PartyID, UserID

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 44,5 44,4 @@ def get_users_by_id(events: List[UserEvent]) -> Dict[UserID, User]:


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/generate_sql_to_delete_user.py => scripts/generate_sql_to_delete_user.py +2 -3
@@ 18,7 18,7 @@ import click
from byceps.services.user import service as user_service
from byceps.typing import UserID

from _util import app_context
from _util import call_with_app_context
from _validators import validate_user_id_format




@@ 70,5 70,4 @@ def generate_delete_statements_for_user(user_id: UserID) -> Iterator[str]:


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/grant_board_access.py => scripts/grant_board_access.py +2 -3
@@ 11,7 11,7 @@ import click
from byceps.services.board import access_control_service, board_service
from byceps.services.board.transfer.models import Board

from _util import app_context
from _util import call_with_app_context
from _validators import validate_user_screen_name




@@ 48,5 48,4 @@ def execute(board, user):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/import_permissions_and_roles.py => scripts/import_permissions_and_roles.py +2 -3
@@ 10,7 10,7 @@ import click

from byceps.services.authorization import impex_service

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 24,5 24,4 @@ def execute(data_file):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/occupy_seat_group.py => scripts/occupy_seat_group.py +2 -3
@@ 11,7 11,7 @@ import click
from byceps.services.seating import seat_group_service
from byceps.services.ticketing import ticket_bundle_service

from _util import app_context
from _util import call_with_app_context


def get_seat_group(ctx, param, seat_group_id):


@@ 44,5 44,4 @@ def execute(seat_group, ticket_bundle):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/remove_user_sessions.py => scripts/remove_user_sessions.py +2 -3
@@ 16,7 16,7 @@ import click

from byceps.services.authentication.session import service as session_service

from _util import app_context
from _util import call_with_app_context


@click.command()


@@ 28,5 28,4 @@ def execute():


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/search_snippets.py => scripts/search_snippets.py +2 -3
@@ 11,7 11,7 @@ import click
from byceps.services.snippet import service as snippet_service
from byceps.services.snippet.transfer.models import Scope

from _util import app_context
from _util import call_with_app_context
from _validators import validate_site




@@ 72,5 72,4 @@ def format_scope(scope):


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)

M scripts/set_current_terms_version.py => scripts/set_current_terms_version.py +2 -3
@@ 16,7 16,7 @@ from byceps.services.terms.dbmodels.version import Version
from byceps.services.terms.transfer.models import DocumentID, VersionID
from byceps.services.terms import document_service, version_service

from _util import app_context
from _util import call_with_app_context


def validate_document_id(ctx, param, value) -> DocumentID:


@@ 96,5 96,4 @@ def _get_version_ids_latest_first(


if __name__ == '__main__':
    with app_context():
        execute()
    call_with_app_context(execute)