switch wcs to django management commands (#83567)
gitea/publik-imio-industrialisation/pipeline/head This commit looks good Details

This commit is contained in:
Frédéric Péters 2023-11-21 12:15:43 +01:00
parent 75f4301241
commit 6e55599667
4 changed files with 23 additions and 36 deletions

View File

@ -31,8 +31,8 @@ install:
cp hobo/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/hobo/environment/management/commands/ 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/ 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/ -cp passerelle/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/passerelle/base/management/commands/
mkdir -p $(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/ cp wcs/*.py $(DESTDIR)$(prefix)/lib/python3/dist-packages/wcs/ctl/management/commands/
dist-bzip2: dist dist-bzip2: dist
-mkdir sdist -mkdir sdist

View File

@ -1,4 +1,3 @@
hobo ALL=(wcs)NOPASSWD:/usr/bin/wcsctl
hobo ALL=(wcs)NOPASSWD:/usr/bin/wcs-manage hobo ALL=(wcs)NOPASSWD:/usr/bin/wcs-manage
hobo ALL=(authentic-multitenant)NOPASSWD:/usr/bin/authentic2-multitenant-manage hobo ALL=(authentic-multitenant)NOPASSWD:/usr/bin/authentic2-multitenant-manage
hobo ALL=(combo)NOPASSWD:/usr/bin/combo-manage hobo ALL=(combo)NOPASSWD:/usr/bin/combo-manage

View File

@ -1,25 +1,22 @@
import os import argparse
import sys import sys
from ..qommon.ctl import Command, make_option from quixote import get_publisher
from wcs.ctl.management.commands import TenantCommand
class Cmd(Command): class Command(TenantCommand):
name = 'has_role'
def __init__(self): def add_arguments(self, parser):
super().__init__([make_option('-d', '--domain', action='store', dest='domain')]) 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): def handle(self, *args, **options):
from .. import publisher domain = options.pop('domain')
self.init_tenant_publisher(domain)
publisher.WcsPublisher.configure(self.config) for role in get_publisher().role_class.select():
publisher = publisher.WcsPublisher.create_publisher(register_tld_names=False)
publisher.set_tenant_by_hostname(sub_options.domain)
for role in publisher.role_class.select():
if role.name == args[0]: if role.name == args[0]:
sys.exit(0) sys.exit(0)
sys.exit(1) sys.exit(1)
Cmd.register()

View File

@ -1,3 +1,4 @@
import argparse
import logging import logging
import os import os
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -18,28 +19,21 @@ from wcs.mail_templates import MailTemplate
from wcs.workflows import Workflow from wcs.workflows import Workflow
from wcs.wscalls import NamedWsCall 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') logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
class Cmd(Command): class Command(TenantCommand):
name = 'imio_import_directory'
def __init__(self): def add_arguments(self, parser):
super().__init__( parser.add_argument('-d', '--domain', '--vhost', required=True, metavar='DOMAIN')
[ parser.add_argument('args', nargs=argparse.REMAINDER)
make_option('-d', '--domain', action='store', dest='domain'),
]
)
def execute(self, base_options, sub_options, args): def handle(self, *args, **options):
from .. import publisher 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.directory = args[0]
self.import_categories() self.import_categories()
self.import_datasources() self.import_datasources()
@ -232,6 +226,3 @@ class Cmd(Command):
if hasattr(formdef, attribute): if hasattr(formdef, attribute):
setattr(existing_formdef, attribute, getattr(formdef, attribute)) setattr(existing_formdef, attribute, getattr(formdef, attribute))
existing_formdef.store(comment='Indus Update') existing_formdef.store(comment='Indus Update')
Cmd.register()