23 |
23 |
over all schemata. The actual command name is expected in the
|
24 |
24 |
class variable COMMAND_NAME of the subclass.
|
25 |
25 |
"""
|
|
26 |
|
26 |
27 |
def __new__(cls, *args, **kwargs):
|
27 |
28 |
"""
|
28 |
29 |
Sets option_list and help dynamically.
|
... | ... | |
32 |
33 |
app_name = get_commands()[obj.COMMAND_NAME]
|
33 |
34 |
if isinstance(app_name, BaseCommand):
|
34 |
35 |
# If the command is already loaded, use it directly.
|
35 |
|
cmdclass = app_name
|
|
36 |
obj._original_command = app_name
|
36 |
37 |
else:
|
37 |
|
cmdclass = load_command_class(app_name, obj.COMMAND_NAME)
|
|
38 |
obj._original_command = load_command_class(app_name, obj.COMMAND_NAME)
|
|
39 |
|
|
40 |
# prepend the command's original help with the info about schemata
|
|
41 |
# iteration
|
|
42 |
obj.help = (
|
|
43 |
"Calls {cmd} for all registered schemata. You can use regular "
|
|
44 |
"{cmd} options.\n\nOriginal help for {cmd}:\n\n{help}".format(
|
|
45 |
cmd=obj.COMMAND_NAME,
|
|
46 |
help=getattr(obj._original_command, 'help', 'none'),
|
|
47 |
)
|
|
48 |
)
|
38 |
49 |
|
39 |
|
# prepend the command's original help with the info about schemata iteration
|
40 |
|
obj.help = "Calls %s for all registered schemata. You can use regular %s options. "\
|
41 |
|
"Original help for %s: %s" % (obj.COMMAND_NAME, obj.COMMAND_NAME, obj.COMMAND_NAME,
|
42 |
|
getattr(cmdclass, 'help', 'none'))
|
43 |
50 |
return obj
|
44 |
51 |
|
45 |
52 |
def add_arguments(self, parser):
|
46 |
53 |
super(BaseTenantCommand, self).add_arguments(parser)
|
47 |
54 |
parser.add_argument("-d", "--domain", dest="domain")
|
48 |
|
parser.add_argument("-p", "--skip-public", dest="skip_public", action="store_true", default=False)
|
|
55 |
parser.add_argument("-p", "--skip-public", dest="skip_public",
|
|
56 |
action="store_true", default=False)
|
|
57 |
# use the privately held reference to the underlying command to invoke
|
|
58 |
# the add_arguments path on this parser instance
|
|
59 |
self._original_command.add_arguments(parser)
|
49 |
60 |
|
50 |
61 |
def execute_command(self, tenant, command_name, *args, **options):
|
51 |
62 |
verbosity = int(options.get('verbosity'))
|
... | ... | |
71 |
82 |
self.execute_command(TenantMiddleware.get_tenant_by_hostname(options['domain']), self.COMMAND_NAME, *args, **options)
|
72 |
83 |
else:
|
73 |
84 |
for tenant in TenantMiddleware.get_tenants():
|
74 |
|
if not(options['skip_public'] and tenant.schema_name == get_public_schema_name()):
|
|
85 |
if not (options['skip_public'] and tenant.schema_name == get_public_schema_name()):
|
75 |
86 |
self.execute_command(tenant, self.COMMAND_NAME, *args, **options)
|
76 |
87 |
|
77 |
88 |
|
78 |
|
-
|