From 6e55599667b16251d8c0a20d1fe3a5d9a1445f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 21 Nov 2023 12:15:43 +0100 Subject: [PATCH] switch wcs to django management commands (#83567) --- Makefile | 4 ++-- debian/sudo-publik-indus | 1 - wcs/has_role.py | 27 ++++++++++++--------------- wcs/imio_import_directory.py | 27 +++++++++------------------ 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 94727cf..1b23ea1 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,8 @@ install: cp hobo/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/hobo/environment/management/commands/ mkdir -p $(DESTDIR)$(prefix)/lib/python3/dist-packages/passerelle/base/management/commands/ -cp passerelle/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/passerelle/base/management/commands/ - mkdir -p $(DESTDIR)$(prefix)/lib/python3/dist-packages/wcs/ctl/ - cp wcs/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/wcs/ctl/ + mkdir -p $(DESTDIR)$(prefix)/lib/python3/dist-packages/wcs/ctl/management/commands/ + cp wcs/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/wcs/ctl/management/commands/ dist-bzip2: dist -mkdir sdist diff --git a/debian/sudo-publik-indus b/debian/sudo-publik-indus index 03fded6..e52d534 100644 --- a/debian/sudo-publik-indus +++ b/debian/sudo-publik-indus @@ -1,4 +1,3 @@ -hobo ALL=(wcs)NOPASSWD:/usr/bin/wcsctl hobo ALL=(wcs)NOPASSWD:/usr/bin/wcs-manage hobo ALL=(authentic-multitenant)NOPASSWD:/usr/bin/authentic2-multitenant-manage hobo ALL=(combo)NOPASSWD:/usr/bin/combo-manage diff --git a/wcs/has_role.py b/wcs/has_role.py index 115aced..ce4163d 100644 --- a/wcs/has_role.py +++ b/wcs/has_role.py @@ -1,25 +1,22 @@ -import os +import argparse import sys -from ..qommon.ctl import Command, make_option +from quixote import get_publisher + +from wcs.ctl.management.commands import TenantCommand -class Cmd(Command): - name = 'has_role' +class Command(TenantCommand): - def __init__(self): - super().__init__([make_option('-d', '--domain', action='store', dest='domain')]) + def add_arguments(self, parser): + parser.add_argument('-d', '--domain', '--vhost', required=True, metavar='DOMAIN') + parser.add_argument('args', nargs=argparse.REMAINDER) - def execute(self, base_options, sub_options, args): - from .. import publisher + def handle(self, *args, **options): + domain = options.pop('domain') + self.init_tenant_publisher(domain) - publisher.WcsPublisher.configure(self.config) - publisher = publisher.WcsPublisher.create_publisher(register_tld_names=False) - publisher.set_tenant_by_hostname(sub_options.domain) - for role in publisher.role_class.select(): + for role in get_publisher().role_class.select(): if role.name == args[0]: sys.exit(0) sys.exit(1) - - -Cmd.register() diff --git a/wcs/imio_import_directory.py b/wcs/imio_import_directory.py index fcc7918..4e6f8a9 100644 --- a/wcs/imio_import_directory.py +++ b/wcs/imio_import_directory.py @@ -1,3 +1,4 @@ +import argparse import logging import os import xml.etree.ElementTree as ET @@ -18,28 +19,21 @@ from wcs.mail_templates import MailTemplate from wcs.workflows import Workflow from wcs.wscalls import NamedWsCall -from ..qommon.ctl import Command, make_option +from wcs.ctl.management.commands import TenantCommand logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -class Cmd(Command): - name = 'imio_import_directory' +class Command(TenantCommand): - def __init__(self): - super().__init__( - [ - make_option('-d', '--domain', action='store', dest='domain'), - ] - ) + def add_arguments(self, parser): + parser.add_argument('-d', '--domain', '--vhost', required=True, metavar='DOMAIN') + parser.add_argument('args', nargs=argparse.REMAINDER) - def execute(self, base_options, sub_options, args): - from .. import publisher + def handle(self, *args, **options): + domain = options.pop('domain') + self.init_tenant_publisher(domain) - publisher.WcsPublisher.configure(self.config) - publisher = publisher.WcsPublisher.create_publisher(register_tld_names=False) - publisher.set_tenant_by_hostname(sub_options.domain) - publisher.substitutions.feed(publisher) self.directory = args[0] self.import_categories() self.import_datasources() @@ -232,6 +226,3 @@ class Cmd(Command): if hasattr(formdef, attribute): setattr(existing_formdef, attribute, getattr(formdef, attribute)) existing_formdef.store(comment='Indus Update') - - -Cmd.register()