From 78ed5e64cba23a1fd5219b51282d7516b40655a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Fri, 29 Mar 2024 03:48:33 +0100 Subject: type manage script --- accounts/utils/console.py | 2 +- manage.py | 34 ++++++++++++++++++---------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/accounts/utils/console.py b/accounts/utils/console.py index cabfc08..8be2cec 100644 --- a/accounts/utils/console.py +++ b/accounts/utils/console.py @@ -82,7 +82,7 @@ class ConsoleForm: _ready = False def __init__( - self, formcls: Callable[..., Form], **kwargs: dict[str, Any] + self, formcls: Callable[..., Form], **kwargs: Any ) -> None: self.form = formcls(meta={"csrf": False}) self._fill(kwargs) diff --git a/manage.py b/manage.py index 597d0e6..486b55a 100755 --- a/manage.py +++ b/manage.py @@ -1,29 +1,30 @@ #!/usr/bin/env python3 -from flask import current_app - from argparse import ArgumentParser from accounts.forms import RegisterForm from accounts.utils.console import ConsoleForm, TablePrinter from accounts.backend.mail.dummy import DummyBackend as DummyMailBackend - +from accounts.models import Account from accounts import create_app +from accounts.app import accounts_app + +from typing import Iterator class ListServices(): """List the configured services.""" - def run(self): + def run(self) -> None: table = TablePrinter(['Name', 'URL']) - table.output([(service.name, service.url) - for service in current_app.all_services]) + table.output([[service.name, service.url] + for service in accounts_app.all_services]) class ListUsers(): """List registered users.""" - def _get_users(self, locked, only_locked): - for user in current_app.user_backend.find(): + def _get_users(self, locked: bool, only_locked: bool) -> Iterator[Account]: + for user in accounts_app.user_backend.find(): user_locked = user.mail.startswith('noreply-disabledaccount-') if user_locked and not (locked or only_locked): continue @@ -32,38 +33,39 @@ class ListUsers(): yield user - def run(self, locked, only_locked): + def run(self, locked: bool, only_locked: bool) -> None: table = TablePrinter(['Name', 'E-Mail', 'Uid']) - table.output([(user.uid, user.mail, user.uidNumber) + table.output([[user.uid, user.mail, user.uidNumber] for user in self._get_users(locked, only_locked)]) class CreateUser(): """Register a user.""" - def run(self, username, mail, ignore_blacklist=False, print_only=False): + def run(self, username: str, mail: str, + ignore_blacklist: bool = False, print_only: bool = False): form = ConsoleForm(RegisterForm, username=username, mail=mail) form.csrf_enabled = False del form.question if ignore_blacklist: - current_app.username_blacklist = [] + accounts_app.username_blacklist = [] if not form.validate(): form.print_errors() return if print_only: - current_app.mail_backend = DummyMailBackend(current_app) + accounts_app.mail_backend = DummyMailBackend(accounts_app) - current_app.mail_backend.send(mail, 'mail/register.txt', - username=username) + accounts_app.mail_backend.send(mail, 'mail/register.txt', + username=username) if not print_only: print('Mail versandt.') -def main(): +def main() -> None: parser = ArgumentParser(description="Spline Accounts") parser.add_argument('-c', '--config', dest='config', required=False) -- cgit v1.2.3-1-g7c22