当前位置: 首页>>代码示例>>Python>>正文


Python management.get_commands方法代码示例

本文整理汇总了Python中django.core.management.get_commands方法的典型用法代码示例。如果您正苦于以下问题:Python management.get_commands方法的具体用法?Python management.get_commands怎么用?Python management.get_commands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.core.management的用法示例。


在下文中一共展示了management.get_commands方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __new__

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def __new__(cls, *args, **kwargs):
        """
        Sets option_list and help dynamically.
        """
        obj = super().__new__(cls, *args, **kwargs)

        app_name = get_commands()[obj.COMMAND_NAME]
        if isinstance(app_name, BaseCommand):
            # If the command is already loaded, use it directly.
            cmdclass = app_name
        else:
            cmdclass = load_command_class(app_name, obj.COMMAND_NAME)

        # prepend the command's original help with the info about schemata iteration
        obj.help = "Calls %s for all registered schemata. You can use regular %s options. " \
                   "Original help for %s: %s" % (obj.COMMAND_NAME, obj.COMMAND_NAME, obj.COMMAND_NAME,
                                                 getattr(cmdclass, 'help', 'none'))
        return obj 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:20,代码来源:__init__.py

示例2: test_command_recognized

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def test_command_recognized():
    assert "testcmd" in get_commands() 
开发者ID:GaretJax,项目名称:django-click,代码行数:4,代码来源:test_adapter.py

示例3: _patch_get_commands

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def _patch_get_commands():
    django_get_commands = management.get_commands

    def patched_get_commands():
        commands = django_get_commands()
        commands.update(_commands)
        return commands

    patched_get_commands.patched = True
    management.get_commands = patched_get_commands 
开发者ID:zenwalker,项目名称:django-micro,代码行数:12,代码来源:django_micro.py

示例4: command

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def command(name=None, command_cls=None):
    if not getattr(management.get_commands, 'patched', False):
        _patch_get_commands()

    if inspect.isfunction(name):
        # Shift arguments if decroator called without brackets
        command_cls = name
        name = None

    def decorator(command_cls):
        command_name = name

        if inspect.isclass(command_cls):
            command_instance = command_cls()
        else:
            # transform function-based command to class
            command_name = name or command_cls.__name__
            command_instance = type('Command', (BaseCommand,), {'handle': command_cls})()

        if not command_name:
            raise DjangoMicroException("Class-based commands requires name argument.")

        # Hack for extracting app name from command (https://goo.gl/1c1Irj)
        command_instance.rpartition = lambda x: [_app_config.module]

        _commands[command_name] = command_instance
        return command_cls

    # allow use decorator directly
    # command('print_hello', PrintHelloCommand)
    if command_cls:
        return decorator(command_cls)

    return decorator 
开发者ID:zenwalker,项目名称:django-micro,代码行数:36,代码来源:django_micro.py

示例5: run_from_argv

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def run_from_argv(self, argv):
        """
        Changes the option_list to use the options from the wrapped command.
        Adds schema parameter to specify which schema will be used when
        executing the wrapped command.
        """
        # load the command object.
        if len(argv) <= 2:
            return

        try:
            app_name = get_commands()[argv[2]]
        except KeyError:
            raise CommandError("Unknown command: %r" % argv[2])

        if isinstance(app_name, BaseCommand):
            # if the command is already loaded, use it directly.
            klass = app_name
        else:
            klass = load_command_class(app_name, argv[2])

        # Ugly, but works. Delete tenant_command from the argv, parse the schema manually
        # and forward the rest of the arguments to the actual command being wrapped.
        del argv[1]
        schema_parser = argparse.ArgumentParser()
        schema_parser.add_argument("-s", "--schema", dest="schema_name", help="specify tenant schema")
        schema_namespace, args = schema_parser.parse_known_args(argv)

        tenant = self.get_tenant_from_options_or_interactive(schema_name=schema_namespace.schema_name)
        connection.set_tenant(tenant)
        klass.run_from_argv(args) 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:33,代码来源:tenant_command.py

示例6: run_from_argv

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def run_from_argv(self, argv):
        """
        Changes the option_list to use the options from the wrapped command.
        """
        # load the command object.
        if len(argv) <= 2:
            return
        try:
            app_name = get_commands()[argv[2]]
        except KeyError:
            raise CommandError("Unknown command: %r" % argv[2])

        if isinstance(app_name, BaseCommand):
            # if the command is already loaded, use it directly.
            klass = app_name
        else:
            klass = load_command_class(app_name, argv[2])

        # Ugly, but works. Delete tenant_command from the argv, parse the schema manually
        # and forward the rest of the arguments to the actual command being wrapped.
        del argv[1]
        schema_parser = argparse.ArgumentParser()
        schema_namespace, args = schema_parser.parse_known_args(argv)
        print(args)

        tenant_model = get_tenant_model()
        tenants = tenant_model.objects.all()
        for tenant in tenants:
            self.stdout.write("Applying command to: %s" % tenant.schema_name)
            connection.set_tenant(tenant)
            klass.run_from_argv(args) 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:33,代码来源:all_tenants_command.py

示例7: get_command_from_arg

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import get_commands [as 别名]
def get_command_from_arg(self, arg):
        *chunks, command = arg.split(".")
        path = ".".join(chunks)
        if not path:
            path = get_commands().get(command)
        try:
            cmd = load_command_class(path, command)
        except Exception:
            raise CommandError("Unknown command: %s" % arg)
        if isinstance(cmd, WrappedSchemaOption):
            raise CommandError("Command '%s' cannot be used in runschema" % arg)
        return cmd 
开发者ID:lorinkoz,项目名称:django-pgschemas,代码行数:14,代码来源:runschema.py


注:本文中的django.core.management.get_commands方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。