From f9ecdc869b1e5cca171a3d08d1b31d2b12da6882 Mon Sep 17 00:00:00 2001 From: Bastien Le Querrec <blq@laquadrature.net> Date: Mon, 15 Apr 2024 00:14:13 +0200 Subject: [PATCH] =?UTF-8?q?cli:=20le=20nom=20de=20l'administration=20analy?= =?UTF-8?q?s=C3=A9e=20n'est=20plus=20une=20option=20mais=20le=20premier=20?= =?UTF-8?q?param=C3=A8tre?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 2 +- Makefile | 48 ++++++++++++++++++++++++------------------------ README.md | 2 +- cli.py | 47 ++++++++++++++++++++++++----------------------- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa93dd4..3063ad7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,7 +78,7 @@ pep8: - source bin/activate - pip install --upgrade -r requirements.txt - /etc/init.d/tor start - - python ./cli.py --pref "${PREF}" + - python ./cli.py "${PREF}" cache: key: $CI_COMMIT_REF_SLUG-$CI_JOB_NAME_SLUG fallback_keys: diff --git a/Makefile b/Makefile index 8933ca7..2d78537 100644 --- a/Makefile +++ b/Makefile @@ -1,51 +1,51 @@ make: ppparis pref04 pref05 pref06 pref09 pref13 pref31 pref33 pref34 pref35 pref38 pref42 pref44 pref59 pref62 pref65 pref66 pref69 pref80 pref81 pref83 pref87 pref976 ppparis: - python cli.py --pref ppparis + python cli.py ppparis pref04: - python cli.py --pref pref04 + python cli.py pref04 pref05: - python cli.py --pref pref05 + python cli.py pref05 pref06: - python cli.py --pref pref06 + python cli.py pref06 pref09: - python cli.py --pref pref09 + python cli.py pref09 pref13: - python cli.py --pref pref13 + python cli.py pref13 pref31: - python cli.py --pref pref31 + python cli.py pref31 pref33: - python cli.py --pref pref33 + python cli.py pref33 pref34: - python cli.py --pref pref34 + python cli.py pref34 pref35: - python cli.py --pref pref35 + python cli.py pref35 pref38: - python cli.py --pref pref38 + python cli.py pref38 pref42: - python cli.py --pref pref42 + python cli.py pref42 pref44: - python cli.py --pref pref44 + python cli.py pref44 pref59: - python cli.py --pref pref59 + python cli.py pref59 pref62: - python cli.py --pref pref62 + python cli.py pref62 pref64: - python cli.py --pref pref64 + python cli.py pref64 pref65: - python cli.py --pref pref65 + python cli.py pref65 pref66: - python cli.py --pref pref66 + python cli.py pref66 pref69: - python cli.py --pref pref69 + python cli.py pref69 pref80: - python cli.py --pref pref80 + python cli.py pref80 pref81: - python cli.py --pref pref81 + python cli.py pref81 pref83: - python cli.py --pref pref83 + python cli.py pref83 pref87: - python cli.py --pref pref87 + python cli.py pref87 pref976: - python cli.py --pref pref976 + python cli.py pref976 lint: pycodestyle --first --show-source --ignore=E501 *.py diff --git a/README.md b/README.md index d72a8f8..3a9587c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ make Attention, le premier lancement prendra plusieurs jours ! Si vous utilisez une CI, vous devez mettre en cache le dossier `data/` afin que les fichiers déjà analysés ne soient pas téléchargés à chaque lancement. -Il est possible de ne lancer l'analyse que pour une seule administration, avec la commande : `./cli.py --pref identifiant` +Il est possible de ne lancer l'analyse que pour une seule administration, avec la commande : `./cli.py identifiant` ## Administrations supportées diff --git a/cli.py b/cli.py index 1b038a1..a2c3315 100755 --- a/cli.py +++ b/cli.py @@ -35,8 +35,8 @@ else: __MASTODON_ACCESS_TOKEN = os.getenv('MASTODON_ACCESS_TOKEN') __MASTODON_INSTANCE = os.getenv('MASTODON_INSTANCE') -# Liste des préfectures supportées -available_prefs = [ +# Liste des administrations supportées +available_administrations = [ 'ppparis', 'pref04', 'pref05', @@ -66,15 +66,13 @@ available_prefs = [ # Début du script parser = argparse.ArgumentParser( prog='cli.py', - description='Télécharge les RAA d\'une préfecture donnée et recherche des mots-clés' + description='Télécharge les RAA d\'une administration donnée et recherche des mots-clés' ) parser.add_argument( - '-p', - '--pref', + 'administration', action='store', - help='identifiant de la préfecture', - required=True, - choices=available_prefs + help='identifiant de l\'administration', + choices=available_administrations ) parser.add_argument( '-k', @@ -130,11 +128,11 @@ parser.add_argument( help='adresses de courrier électronique destinataires des notifications (séparées par une virgule)' ) -for pref in available_prefs: +for administration in available_administrations: parser.add_argument( - f'--{pref}-email-to', + f'--{administration}-email-to', action='store', - help=f'adresses de courrier électronique destinataires des notifications (séparées par une virgule) uniquement si l\'analyse concerne {pref} (s\'ajoute à celles précisées dans --email-to)' + help=f'adresses de courrier électronique destinataires des notifications (séparées par une virgule) uniquement si l\'analyse concerne {administration} (s\'ajoute à celles précisées dans --email-to)' ) parser.add_argument( @@ -203,24 +201,27 @@ if args.mastodon_access_token: if args.mastodon_instance: __MASTODON_INSTANCE = args.mastodon_instance -__DATA_DIR = f'{__DATA_DIR_ROOT}{args.pref}/' +__DATA_DIR = f'{__DATA_DIR_ROOT}{args.administration}/' # On calcule la liste des mails à notifier (liste générale EMAIL_TO + liste -# prefecture EMAIL_TO_PREF**) -__PREF_EMAIL_TO = '' -pref_var_name = f'{args.pref}_EMAIL_TO'.upper() -if os.getenv(pref_var_name): - __PREF_EMAIL_TO = os.getenv(pref_var_name) +# administration EMAIL_TO_ADMINISTRATION**) +__ADMINISTRATION_EMAIL_TO = '' +administration_var_name = f'{args.administration}_EMAIL_TO'.upper() +if os.getenv(administration_var_name): + __ADMINISTRATION_EMAIL_TO = os.getenv(administration_var_name) else: for arg in vars(args).items(): - if arg[0] == f'{args.pref}_email_to': - __PREF_EMAIL_TO = arg[1] + if arg[0] == f'{args.administration}_email_to': + __ADMINISTRATION_EMAIL_TO = arg[1] -if __PREF_EMAIL_TO and not __PREF_EMAIL_TO == '': - __EMAIL_TO = f'{__EMAIL_TO},{__PREF_EMAIL_TO}' +if __ADMINISTRATION_EMAIL_TO and not __ADMINISTRATION_EMAIL_TO == '': + if __EMAIL_TO: + __EMAIL_TO = f'{__EMAIL_TO},{__ADMINISTRATION_EMAIL_TO}' + else: + __EMAIL_TO = __ADMINISTRATION_EMAIL_TO -module = importlib.import_module(f'RAAspotter_{args.pref}') -raa_spotter = getattr(module, f'RAAspotter_{args.pref}')(__DATA_DIR) +module = importlib.import_module(f'RAAspotter_{args.administration}') +raa_spotter = getattr(module, f'RAAspotter_{args.administration}')(__DATA_DIR) raa_spotter.not_before = __NOT_BEFORE raa_spotter.configure_mailer(__SMTP_HOSTNAME, __SMTP_USERNAME, __SMTP_PASSWORD, __SMTP_PORT, __SMTP_STARTTLS, __SMTP_SSL, -- GitLab