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


Python management.ManagementUtility方法代码示例

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


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

示例1: create_project

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import ManagementUtility [as 别名]
def create_project(args):
    """
    Create a new django project using the longclaw template
    """

    # Make sure given name is not already in use by another python package/module.
    try:
        __import__(args.project_name)
    except ImportError:
        pass
    else:
        sys.exit("'{}' conflicts with the name of an existing "
                 "Python module and cannot be used as a project "
                 "name. Please try another name.".format(args.project_name))

    # Get the longclaw template path
    template_path = path.join(path.dirname(longclaw.__file__), 'project_template')

    utility = ManagementUtility((
        'django-admin.py',
        'startproject',
        '--template={}'.format(template_path),
        '--extension=html,css,js,py,txt',
        args.project_name
    ))
    utility.execute()
    print("{} has been created.".format(args.project_name)) 
开发者ID:JamesRamm,项目名称:longclaw,代码行数:29,代码来源:longclaw.py

示例2: run

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import ManagementUtility [as 别名]
def run(self, project_name=None, dest_dir=None):
        # Make sure given name is not already in use by another python package/module.
        try:
            __import__(project_name)
        except ImportError:
            pass
        else:
            sys.exit("'%s' conflicts with the name of an existing "
                     "Python module and cannot be used as a project "
                     "name. Please try another name." % project_name)

        print("Creating a Ra project called %(project_name)s" % {'project_name': project_name})  # noqa

        # Create the project from the Ra template using startapp

        # First find the path to Ra
        import ra
        ra_path = os.path.dirname(ra.__file__)
        template_path = os.path.join(ra_path, 'project_template', 'project_template')

        # Call django-admin startproject
        utility_args = ['django-admin.py',
                        'startproject',
                        '--template=' + template_path,
                        '--ext=html,rst',
                        project_name]

        if dest_dir:
            utility_args.append(dest_dir)

        utility = ManagementUtility(utility_args)
        utility.execute()

        print("Success! %(project_name)s has been created" % {'project_name': project_name})  # noqa 
开发者ID:ra-systems,项目名称:django-ra-erp,代码行数:36,代码来源:ra.py

示例3: run

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import ManagementUtility [as 别名]
def run(self, project_name=None, dest_dir=None):
        # Make sure given name is not already in use by another python package/module.
        try:
            __import__(project_name)
        except ImportError:
            pass
        else:
            sys.exit("'%s' conflicts with the name of an existing "
                     "Python module and cannot be used as a project "
                     "name. Please try another name." % project_name)

        print("Creating a Wagtail project called %(project_name)s" % {'project_name': project_name})  # noqa

        # Create the project from the Wagtail template using startapp

        # First find the path to Wagtail
        import wagtail
        wagtail_path = os.path.dirname(wagtail.__file__)
        template_path = os.path.join(wagtail_path, 'project_template')

        # Call django-admin startproject
        utility_args = ['django-admin.py',
                        'startproject',
                        '--template=' + template_path,
                        '--ext=html,rst',
                        '--name=Dockerfile',
                        project_name]

        if dest_dir:
            utility_args.append(dest_dir)

        utility = ManagementUtility(utility_args)
        utility.execute()

        print("Success! %(project_name)s has been created" % {'project_name': project_name})  # noqa 
开发者ID:wagtail,项目名称:wagtail,代码行数:37,代码来源:wagtail.py

示例4: cmd_e2e

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import ManagementUtility [as 别名]
def cmd_e2e(self, cmd, stdin=None, stdout=None, stderr=None):
        """Call a management command the way manage.py does.

        Unlike call_command, this method also tests the argparse configuration of the called command.
        """
        stdout = stdout or StringIO()
        stderr = stderr or StringIO()
        if stdin is None:
            stdin = StringIO()

        with patch('sys.stdin', stdin), patch('sys.stdout', stdout), patch('sys.stderr', stderr):
            util = ManagementUtility(['manage.py', ] + list(cmd))
            util.execute()

        return stdout.getvalue(), stderr.getvalue() 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:17,代码来源:base.py

示例5: test_system_exit

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import ManagementUtility [as 别名]
def test_system_exit(self):
        """ Exception raised in a command should raise CommandError with
            call_command, but SystemExit when run from command line
        """
        with self.assertRaises(CommandError):
            management.call_command('dance', example="raise")
        dance.Command.requires_system_checks = False
        try:
            with captured_stderr() as stderr, self.assertRaises(SystemExit):
                management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
        finally:
            dance.Command.requires_system_checks = True
        self.assertIn("CommandError", stderr.getvalue()) 
开发者ID:nesdis,项目名称:djongo,代码行数:15,代码来源:tests.py

示例6: _run_autocomplete

# 需要导入模块: from django.core import management [as 别名]
# 或者: from django.core.management import ManagementUtility [as 别名]
def _run_autocomplete(self):
        util = ManagementUtility(argv=sys.argv)
        with captured_stdout() as stdout:
            try:
                util.autocomplete()
            except SystemExit:
                pass
        return stdout.getvalue().strip().split('\n') 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:tests.py


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