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


Python base.CommandError方法代码示例

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


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

示例1: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def handle(self, *args, **options):
        """Handle the command invocation."""
        email = getattr(settings, 'ADMIN_EMAIL_ADDRESS', None)
        username = getattr(settings, 'ADMIN_USERNAME', None)
        password = getattr(settings, 'ADMIN_PASSWORD', None)

        if not email or not username or not password:
            raise CommandError('ADMIN_USERNAME, ADMIN_PASSWORD, and ADMIN_EMAIL_ADDRESS must be set')

        admin = User(username=username, email=email)
        admin.set_password(password)
        admin.is_superuser = True
        admin.is_staff = True
        admin.save()

        msg = 'Successfully configured admin %s (%s)' % (username, email)
        self.stdout.write(self.style.SUCCESS(msg))  # pylint: disable=no-member 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:19,代码来源:createadmin.py

示例2: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def handle(self, *args, **options):
        """Handle the command invocation."""
        if options['frequency'] == 'daily':
            self.report(send_digest_emails(DigestFrequency.daily))
        elif options['frequency'] == 'weekly':
            digest_day = getattr(settings, 'DIGEST_WEEKLY_DAY')
            current_day = timezone.now().weekday()
            if current_day == digest_day or options['force']:
                if current_day != digest_day and options['force']:
                    msg = 'Forcing weekly digest to be sent (scheduled=%s, current=%s)' % (digest_day, current_day)
                    self.stdout.write(self.style.WARNING(msg))  # pylint: disable=no-member
                self.report(send_digest_emails(DigestFrequency.weekly))
            else:
                msg = 'Skipping weekly digest until day %s (current=%s)' % (digest_day, current_day)
                self.stdout.write(self.style.WARNING(msg))  # pylint: disable=no-member
        else:
            raise CommandError('Expected frequency "daily" or "weekly"') 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:19,代码来源:senddigest.py

示例3: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def handle(self, *args, **options):
        """Handle the command invocation."""
        site_id = getattr(settings, 'SITE_ID', None)
        site_name = getattr(settings, 'SITE_NAME', None)
        site_domain = getattr(settings, 'SITE_DOMAIN', None)

        if not site_id:
            raise CommandError('No SITE_ID specified in project settings')
        if not site_name:
            raise CommandError('No SITE_NAME specified in project settings')
        if not site_domain:
            raise CommandError('No SITE_DOMAIN specified in project settings')

        try:
            site = Site.objects.get(pk=site_id)
        except Site.DoesNotExist:  # pylint: disable=no-member
            raise CommandError('Site "%s" does not exist' % site_id)

        site.name = site_name
        site.domain = site_domain
        site.save()

        msg = 'Successfully configured site #%s; name: "%s"; domain: %s' % (site_id, site_name, site_domain)
        self.stdout.write(self.style.SUCCESS(msg))  # pylint: disable=no-member 
开发者ID:twschiller,项目名称:open-synthesis,代码行数:26,代码来源:setname.py

示例4: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def handle(self, *args, **options):
        """transfer project"""
        saved_variant_guid = options['saved_variant_guid']
        variant_id = options['variant_id']

        saved_variant = SavedVariant.objects.get(guid=saved_variant_guid)

        if input('Are you sure you want to update {}-{}-{} to {} (y/n)? '.format(
                saved_variant.xpos_start, saved_variant.ref, saved_variant.alt, variant_id)) != 'y':
            raise CommandError('Error: user did not confirm')

        es_variant = get_single_es_variant([saved_variant.family], variant_id, return_all_queried_families=True)

        saved_variant.xpos_start = es_variant['xpos']
        saved_variant.ref = es_variant['ref']
        saved_variant.alt = es_variant['alt']
        saved_variant.saved_variant_json = es_variant
        saved_variant.save()

        logger.info('---Done---') 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:22,代码来源:lift_variant_to_hg38.py

示例5: test_command_error_unmatched_sample

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def test_command_error_unmatched_sample(self, mock_get_es_samples, mock_logger):
        mock_get_es_samples.return_value = ['ID_NOT_EXIST'], INDEX_METADATA

        with self.assertRaises(CommandError) as ce:
            call_command('lift_project_to_hg38', '--project={}'.format(PROJECT_NAME),
                    '--es-index={}'.format(ELASTICSEARCH_INDEX))

        self.assertEqual(str(ce.exception), 'Matches not found for ES sample ids: ID_NOT_EXIST.')

        calls = [
            mock.call('Updating project genome version for {}'.format(PROJECT_NAME)),
            mock.call('Validating es index test_index')
        ]
        mock_logger.info.assert_has_calls(calls)

        mock_get_es_samples.assert_called_with(ELASTICSEARCH_INDEX) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:18,代码来源:lift_project_to_hg38_2_3_tests.py

示例6: test_command_error_missing_families

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def test_command_error_missing_families(self, mock_get_es_samples, mock_logger):
        mock_get_es_samples.return_value = ['HG00731', 'HG00732', 'HG00733'], INDEX_METADATA

        with self.assertRaises(CommandError) as ce:
            call_command('lift_project_to_hg38', '--project={}'.format(PROJECT_NAME),
                    '--es-index={}'.format(ELASTICSEARCH_INDEX))

        self.assertEqual(str(ce.exception),
            'The following families have saved variants but are missing from the callset: 1.')

        calls = [
            mock.call('Updating project genome version for {}'.format(PROJECT_NAME)),
            mock.call('Validating es index test_index'),
        ]
        mock_logger.info.assert_has_calls(calls)

        mock_get_es_samples.assert_called_with(ELASTICSEARCH_INDEX) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:19,代码来源:lift_project_to_hg38_2_3_tests.py

示例7: test_missing_required_args

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def test_missing_required_args(self):
        out = StringIO()
        with self.assertRaises(CommandError) as err:
            call_command('add_project_tag', stdout = out)
        self.assertIn(str(err.exception), ['Error: argument --project is required',
             'Error: the following arguments are required: --project, --name, --order'])

        with self.assertRaises(CommandError) as err:
            call_command('add_project_tag',
                '--project={}'.format(TAG_ARGUMENTS["project"]),
                stdout = out)
        self.assertIn(str(err.exception), ['Error: argument --name is required',
             'Error: the following arguments are required: --name, --order'])

        with self.assertRaises(CommandError) as err:
            call_command('add_project_tag',
                '--project={}'.format(TAG_ARGUMENTS["project"]),
                '--name={}'.format(TAG_ARGUMENTS["name"]),
                stdout = out)
        self.assertIn(str(err.exception), ['Error: argument --order is required',
             'Error: the following arguments are required: --order']) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:23,代码来源:add_project_tag_2_3_tests.py

示例8: test_command

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def test_command(self, mock_single_es_variants, mock_logger, mock_input):
        # Test user did not confirm.
        mock_input.return_value = 'n'
        with self.assertRaises(CommandError) as ce:
            call_command('lift_variant_to_hg38', SAVED_VARIANT_GUID, VARIANT_ID)

        self.assertEqual(str(ce.exception), 'Error: user did not confirm')

        # Test user did confirm.
        mock_single_es_variants.return_value = PARSED_VARIANTS[0]
        mock_input.return_value = 'y'
        call_command('lift_variant_to_hg38', SAVED_VARIANT_GUID, VARIANT_ID)
        mock_logger.info.assert_called_with('---Done---')

        saved_variant = SavedVariant.objects.get(guid = SAVED_VARIANT_GUID)
        mock_single_es_variants.assert_called_with([saved_variant.family], VARIANT_ID,
                                                   return_all_queried_families = True)

        self.assertListEqual(
            [PARSED_VARIANTS[0]['xpos'], PARSED_VARIANTS[0]['ref'], PARSED_VARIANTS[0]['alt'], PARSED_VARIANTS[0]],
            [saved_variant.xpos_start, saved_variant.ref, saved_variant.alt, saved_variant.saved_variant_json]) 
开发者ID:macarthur-lab,项目名称:seqr,代码行数:23,代码来源:lift_variant_to_hg38_2_3_tests.py

示例9: test_install_unavailable_package

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def test_install_unavailable_package(tmpdir, settings, staticsite_path):
    remote_catalog_file = tmpdir.join('source').join('catalog.yml')
    remote_catalog_file.write_text('all: {}', 'utf-8')

    call_command(
        'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
        'file://{}'.format(remote_catalog_file.strpath))
    call_command('catalog', 'cache', 'update')

    install_dir = Path(settings.CATALOG_NGINX_INSTALL_DIR)
    assert install_dir.join('the-site').check(exists=False)

    with pytest.raises(CommandError) as excinfo:
        call_command('catalog', 'install', 'the-site')

    assert 'No such package: the-site' in excinfo.exconly()
    assert install_dir.join('the-site').check(exists=False) 
开发者ID:ideascube,项目名称:ideascube,代码行数:19,代码来源:test_catalog_command.py

示例10: test_upgrade_unavailable_package

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def test_upgrade_unavailable_package(tmpdir, settings, staticsite_path):
    remote_catalog_file = tmpdir.join('source').join('catalog.yml')
    remote_catalog_file.write_text('all: {}', 'utf-8')

    call_command(
        'catalog', 'remotes', 'add', 'foo', 'Content from Foo',
        'file://{}'.format(remote_catalog_file.strpath))
    call_command('catalog', 'cache', 'update')

    install_dir = Path(settings.CATALOG_NGINX_INSTALL_DIR)
    assert install_dir.join('the-site').check(exists=False)

    with pytest.raises(CommandError) as excinfo:
        call_command('catalog', 'upgrade', 'the-site')

    assert 'No such package: the-site' in excinfo.exconly()
    assert install_dir.join('the-site').check(exists=False) 
开发者ID:ideascube,项目名称:ideascube,代码行数:19,代码来源:test_catalog_command.py

示例11: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def handle(self, addrport=None, *args, **options):

        # deprecation warning to announce future deletion in R21
        util.warn("""This command is deprecated.

        You should now run your application with the WSGI interface
        installed with your project. Ex.:

            gunicorn myproject.wsgi:application

        See https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/gunicorn/
        for more info.""")

        if args:
            raise CommandError('Usage is run_gunicorn %s' % self.args)

        if addrport:
            sys.argv = sys.argv[:-1]
            options['bind'] = addrport

        admin_media_path = options.pop('admin_media_path', '')

        DjangoApplicationCommand(options, admin_media_path).run() 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:run_gunicorn.py

示例12: get_confirmation

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def get_confirmation(self):
        """Get user confirmation to proceed."""
        if self.clear:
            action = "This will DELETE ALL FILES in this location!"
        else:
            action = "This will overwrite existing files!"

        message = (
            "\n"
            "You have requested to collect static files at the destination\n"
            "location as specified in your settings\n"
            "\n"
            "    {destination}\n"
            "\n"
            "{action}\n"
            "Are you sure you want to do this?\n"
            "\n"
            "Type 'yes' to continue, or 'no' to cancel: ".format(
                destination=self.destination_path, action=action,
            )
        )

        if input("".join(message)) != "yes":
            raise CommandError("Collecting tools cancelled.") 
开发者ID:genialis,项目名称:resolwe,代码行数:26,代码来源:collecttools.py

示例13: handle

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

        print('Populate Genes!')
        populate_genes()
        print('Populate Diseases from OMIM!')
        populate_diseases()
        #populate diseases from OMIM
        print('Populate Diseases from CGD!')
        populate_CGD()
        #populate dieases from CGD
        #populate dieases from CGD


        # for poll_id in args:
        #     try:
        #         poll = Poll.objects.get(pk=int(poll_id))
        #     except Poll.DoesNotExist:
        #         raise CommandError('Poll "%s" does not exist' % poll_id)

        #     poll.opened = False
        #     poll.save()

        #     self.stdout.write('Successfully closed poll "%s"' % poll_id) 
开发者ID:raonyguimaraes,项目名称:mendelmd,代码行数:25,代码来源:populate.py

示例14: gettext_popen_wrapper

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def gettext_popen_wrapper(args, os_err_exc_type=CommandError, stdout_encoding="utf-8"):
    """
    Makes sure text obtained from stdout of gettext utilities is Unicode.
    """
    # This both decodes utf-8 and cleans line endings. Simply using
    # popen_wrapper(universal_newlines=True) doesn't properly handle the
    # encoding. This goes back to popen's flaky support for encoding:
    # https://bugs.python.org/issue6135. This is a solution for #23271, #21928.
    # No need to do anything on Python 2 because it's already a byte-string there.
    manual_io_wrapper = six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING

    stdout, stderr, status_code = popen_wrapper(args, os_err_exc_type=os_err_exc_type,
                                                universal_newlines=not manual_io_wrapper)
    if manual_io_wrapper:
        stdout = io.TextIOWrapper(io.BytesIO(stdout), encoding=stdout_encoding).read()
    if six.PY2:
        stdout = stdout.decode(stdout_encoding)
    return stdout, stderr, status_code 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:makemessages.py

示例15: handle

# 需要导入模块: from django.core.management import base [as 别名]
# 或者: from django.core.management.base import CommandError [as 别名]
def handle(self, **options):
        project_name, target = options.pop('name'), options.pop('directory')
        self.validate_name(project_name, "project")

        # Check that the project_name cannot be imported.
        try:
            import_module(project_name)
        except ImportError:
            pass
        else:
            raise CommandError("%r conflicts with the name of an existing "
                               "Python module and cannot be used as a "
                               "project name. Please try another name." %
                               project_name)

        # Create a random SECRET_KEY to put it in the main settings.
        chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
        options['secret_key'] = get_random_string(50, chars)

        super(Command, self).handle('project', project_name, target, **options) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:startproject.py


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