Projet

Général

Profil

0001-multitenant-add-delete_tenant-command.patch

Jean-Baptiste Jaillet, 20 mars 2017 16:14

Télécharger (1,67 ko)

Voir les différences:

Subject: [PATCH] multitenant: add delete_tenant command

 .../management/commands/delete_tenant.py           | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 hobo/multitenant/management/commands/delete_tenant.py
hobo/multitenant/management/commands/delete_tenant.py
1
import sys
2
from optparse import make_option
3

  
4
from django.core.management.base import CommandError, BaseCommand
5
from hobo.multitenant.middleware import TenantMiddleware
6

  
7

  
8
class Command(BaseCommand):
9
    help = "Delete tenant(s) by hostname(s)"
10
    args = ['...']
11
    option_list = BaseCommand.option_list + (
12
		make_option('--force-drop', action='store_true', default=False,
13
                    help='If you want the schema to be deleted from database'),
14
    )
15

  
16
    def handle(self, *args, **options):
17

  
18
        if not args:
19
            raise CommandError("you must give at least one tenant hostname")
20

  
21
        # if - is given on the command line, get list of hostnames from stdin
22
        if '-' in args:
23
            args = list(args)
24
            args.remove('-')
25
            args.extend([x.strip() for x in sys.stdin.readlines()])
26
        for hostname in args:
27
            tenant = TenantMiddleware.get_tenant_by_hostname(hostname)
28
            tenant.delete(force_drop=options['force_drop'])
29

  
0
-