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


Python base.BaseCommand方法代码示例

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


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

示例1: __new__

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [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: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.
        """

        new_password = options.get('password')

        try:
            user = User.objects.get(username='admin')
            if options.get('force'):
                user.first_name = 'Admin'
                user.last_name = 'User'
                user.set_password(new_password)
                user.save()
            else:
                user = None
                print('Existing admin user password left unchanged. Use --force flag to reset.')
        except User.DoesNotExist:
            user = User.objects.create_superuser(username='admin', first_name='Admin', last_name='User', email='',
                                                 password=new_password)

        if user:
            print('Superuser admin password: %s' % (new_password,)) 
开发者ID:ngageoint,项目名称:scale,代码行数:24,代码来源:scale_superuser.py

示例3: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the ingest process.
        """

        # Register a listener to handle clean shutdowns
        signal.signal(signal.SIGTERM, self._onsigterm)

        ingest_id = options.get('ingest_id')

        logger.info('Command starting: scale_ingest')
        logger.info('Ingest ID: %i', ingest_id)
        try:
            ingest_job.perform_ingest(ingest_id)
        except:
            logger.exception('Ingest caught unexpected error, exit code 1 returning')
            sys.exit(1)
        logger.info('Command completed: scale_ingest') 
开发者ID:ngageoint,项目名称:scale,代码行数:21,代码来源:scale_ingest.py

示例4: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the Scale batch creation process.
        """

        batch_id = options.get('batch_id')

        logger.info('Command starting: scale_batch_creator - Batch ID: %i', batch_id)

        # Schedule all the batch recipes
        try:
            batch = Batch.objects.get(id=batch_id)
            CommandMessageManager().send_messages([create_batch_recipes_message(batch_id)])
        except Batch.DoesNotExist:
            logger.exception('Unable to find batch: %i', batch_id)
            sys.exit(1)

        logger.info('Command completed: scale_batch_creator') 
开发者ID:ngageoint,项目名称:scale,代码行数:21,代码来源:scale_batch_creator.py

示例5: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the scheduler.
        """

        # Register a listener to handle clean shutdowns
        signal.signal(signal.SIGTERM, self._onsigterm)

        # Set up global shutdown
        global GLOBAL_SHUTDOWN
        GLOBAL_SHUTDOWN = self._shutdown

        logger.info('Scale Scheduler %s', settings.VERSION)

        self.run_scheduler(settings.MESOS_MASTER) 
开发者ID:ngageoint,项目名称:scale,代码行数:18,代码来源:scale_scheduler.py

示例6: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the command.
        """

        logger.info('Command starting: scale_message_handler')

        self.running = True

        logger.info('Initializing message handler')
        logger.info('Caching builtin errors...')
        Error.objects.cache_builtin_errors()
        logger.info('Initialization complete, ready to process messages')
        
        # Set the signal handler
        signal.signal(signal.SIGINT, self.interupt)
        signal.signal(signal.SIGTERM, self.interupt)

        manager = CommandMessageManager()

        while self.running:
            manager.receive_messages()

        logger.info('Command completed: scale_message_handler') 
开发者ID:ngageoint,项目名称:scale,代码行数:27,代码来源:scale_message_handler.py

示例7: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the command.
        """

        count = options.get('count')
        if not count:
            count = 1

        logger.info('Command starting: scale_echo_message - sending {} message(s)'.format(count))

        manager = CommandMessageManager()
        messages = []
        for x in range(count):
            messages.append(EchoCommandMessage.from_json(
                {'message': 'Greetings, this is echo #{} at {}!'.format(x + 1, datetime.utcnow())}))
                
        
        manager.send_messages(messages)

        logger.info('Command completed: scale_echo_message') 
开发者ID:ngageoint,项目名称:scale,代码行数:24,代码来源:scale_echo_message.py

示例8: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the command.
        """

        body = options.get('body')
        type = options.get('type')
        count = options.get('count')
        if not count:
            count = 1

        logger.info('Command starting: scale_send_message')

        Message = get_message_type(type)

        manager = CommandMessageManager()
        messages = [Message.from_json(body) for _ in range(count)]
        manager.send_messages(messages)

        logger.info('Command completed: scale_send_message') 
开发者ID:ngageoint,项目名称:scale,代码行数:23,代码来源:scale_send_message.py

示例9: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the file delete process.
        """

        logger.info('Command starting: scale_delete_file')

        file_id = options.get('file_id')

        # Attempt to fetch the file model
        try:
            scale_file = ScaleFile.objects.get(pk=file_id)
        except ScaleFile.DoesNotExist:
            logger.exception('Stored file does not exist: %s', file_id)
            sys.exit(1)

        try:
            ScaleFile.objects.delete_files([scale_file])
        except:
            logger.exception('Unknown error occurred, exit code 1 returning')
            sys.exit(1)
        logger.info('Command completed: scale_delete_file') 
开发者ID:ngageoint,项目名称:scale,代码行数:25,代码来源:scale_delete_file.py

示例10: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.

        This method starts the file move process.
        """

        logger.info('Command starting: scale_move_file')

        file_id = options.get('file_id')
        remote_path = options.get('remote_path')
        
        # Attempt to fetch the file model
        try:
            scale_file = ScaleFile.objects.get(pk=file_id)
        except ScaleFile.DoesNotExist:
            logger.exception('Stored file does not exist: %s', file_id)
            sys.exit(1)

        try:
            ScaleFile.objects.move_files([FileMove(scale_file, remote_path)])
        except:
            logger.exception('Unknown error occurred, exit code 1 returning')
            sys.exit(1)
        logger.info('Command completed: scale_move_file') 
开发者ID:ngageoint,项目名称:scale,代码行数:26,代码来源:scale_move_file.py

示例11: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """See :meth:`django.core.management.base.BaseCommand.handle`.
        """

        logger.info('Spinning roulette wheel...')
        time.sleep(1)  # One second
        random.seed()
        result = random.randint(0, 1)

        try:
            if result:
                logger.info('Landed on black')
            else:
                logger.error('Landed on red')
                raise TestException()
        except ScaleError as err:
            sys.exit(err.exit_code) 
开发者ID:ngageoint,项目名称:scale,代码行数:19,代码来源:scale_roulette.py

示例12: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [as 别名]
def handle(self, *args, **options):
        """Entry point for BaseCommand."""
        config_path = options.get("config_path")
        dry_run = options.get("dry_run")
        force = options.get("force")
        stdout = options.get("stdout")
        if stdout is None:
            stdout = sys.stdout

        def options_handler(options_block):
            self.migrate_forwarders(options_block, dry_run, stdout)
            self.migrate_dnssec_validation(options_block, dry_run, stdout)

        try:
            edit_options(config_path, stdout, dry_run, force, options_handler)
        except ValueError as exc:
            raise CommandError(str(exc)) from None 
开发者ID:maas,项目名称:maas,代码行数:19,代码来源:edit_named_options.py

示例13: command

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [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

示例14: run_from_argv

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [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

示例15: run_from_argv

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import BaseCommand [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


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