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


Python management.ManagementUtility类代码示例

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


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

示例1: start

def start (args):
    # if a specific conf has been provided (which it
    # will be), if we're inside the django reloaded
    if "RAPIDSMS_INI" in os.environ:
        ini = os.environ["RAPIDSMS_INI"]
    
    # use a local ini (for development)
    # if one exists, to avoid everyone
    # having their own rapidsms.ini
    elif os.path.isfile("local.ini"):
        ini = "local.ini"
    
    # otherwise, fall back
    else: ini = "rapidsms.ini"

    # add the ini path to the environment, so we can
    # access it globally, including any subprocesses
    # spawned by django
    os.environ["RAPIDSMS_INI"] = ini
    os.environ["DJANGO_SETTINGS_MODULE"] = "rapidsms.webui.settings"

    # read the config, which is shared
    # between the back and frontend
    conf = Config(ini)
    
    # if we found a config ini, try to configure Django
    if conf.sources:
        # This builds the django config from rapidsms.config, in a 
        # round-about way.
        # Can't do it until env[RAPIDSMS_INI] is defined
        from rapidsms.webui import settings 
        
        import_local_settings(settings, ini)

        # whatever we're doing, we'll need to call
        # django's setup_environ, to configure the ORM
        
        from django.core.management import setup_environ, execute_manager
        setup_environ(settings)
    else:
        settings = None

    # if one or more arguments were passed, we're
    # starting up django -- copied from manage.py
    if len(args) < 2:
        print "Commands: route, startproject <name>, startapp <name>"
        sys.exit(1)

    if hasattr(Manager, args[1]):
        handler = getattr(Manager(), args[1])
        handler(conf, *args[2:])
    elif settings:
        # none of the commands were recognized,
        # so hand off to Django
        
        from django.core.management import ManagementUtility
        # The following is equivalent to django's "execute_manager(settings)"
        # only without overriding RapidSMS webui settings
        utility = ManagementUtility()
        utility.execute()
开发者ID:ITIDO,项目名称:rapidsms,代码行数:60,代码来源:manager.py

示例2: report_data

def report_data(dumper):
    """
    Fetches data from management commands and reports it to dumper.

    :type dumper _xml.XmlDumper
    :param dumper: destination to report
    """
    utility = ManagementUtility()
    for command_name in get_commands().keys():
        try:
            command = utility.fetch_command(command_name)
        except ImproperlyConfigured:
            continue  # TODO: Log somehow

        assert isinstance(command, BaseCommand)

        use_argparse = False
        try:
            use_argparse = command.use_argparse
        except AttributeError:
            pass
        dumper.start_command(command_name=command_name,
                             command_help_text=str(command.usage("").replace("%prog", command_name)))
        module_to_use = _argparse if use_argparse else _optparse # Choose appropriate module: argparse, optparse
        module_to_use.process_command(dumper, command, command.create_parser("", command_name))
        dumper.close_command()
开发者ID:machao657,项目名称:intellij-community,代码行数:26,代码来源:parser.py

示例3: run

    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:Henk-JanVanHasselaar,项目名称:wagtail,代码行数:35,代码来源:wagtail.py

示例4: handle

    def handle(self, *args, **options):
        """
        Run and profile the specified management command with the provided
        arguments.
        """
        if not len(args):
            self.print_help(sys.argv[0], 'profile')
            sys.exit(1)
        if not options['sort'] and not options['path']:
            self.stdout.write('Output file path is required for call graph generation')
            sys.exit(1)

        command_name = args[0]
        utility = ManagementUtility(sys.argv)
        command = utility.fetch_command(command_name)
        parser = command.create_parser(sys.argv[0], command_name)
        command_options, command_args = parser.parse_args(list(args[1:]))

        if command_name == 'test' and settings.TEST_RUNNER == 'django_nose.NoseTestSuiteRunner':
            # Ugly hack: make it so django-nose won't have nosetests choke on
            # our parameters
            BaseCommand.option_list += self.custom_options

        if options['backend'] == 'yappi':
            import yet_another_django_profiler.yadp_yappi as yadp_yappi
            profiler = yadp_yappi.YappiProfile()
        else:
            profiler = cProfile.Profile()

        atexit.register(output_results, profiler, options, self.stdout)
        profiler.runcall(call_command, command_name, *command_args, **command_options.__dict__)
        sys.exit(0)
开发者ID:traff,项目名称:yet-another-django-profiler,代码行数:32,代码来源:profile.py

示例5: manage

def manage(command, args=None, as_thread=False):
    """
    Run a django command on the kalite project

    :param command: The django command string identifier, e.g. 'runserver'
    :param args: List of options to parse to the django management command
    :param as_thread: Runs command in thread and returns immediately
    """

    if not args:
        args = []

    args = update_default_args(["--traceback"], args)

    if not as_thread:
        utility = ManagementUtility([os.path.basename(sys.argv[0]), command] + args)
        # This ensures that 'kalite' is printed in help menus instead of
        # 'kalite' or 'kalite.__main__' (a part from the top most text in `kalite manage help`
        utility.prog_name = 'kalite manage'
        utility.execute()
    else:
        get_commands()  # Needed to populate the available commands before issuing one in a thread
        thread = ManageThread(command, args=args, name=" ".join([command] + args))
        thread.start()
        return thread
开发者ID:ruimalheiro,项目名称:ka-lite,代码行数:25,代码来源:cli.py

示例6: _run_autocomplete

 def _run_autocomplete(self):
     util = ManagementUtility(argv=sys.argv)
     try:
         util.autocomplete()
     except SystemExit:
         pass
     return self.output.getvalue().strip().split("\n")
开发者ID:abdulhaq-e,项目名称:django,代码行数:7,代码来源:tests.py

示例7: manage

def manage(command, args=[], in_background=False):
    """
    Run a django command on the kalite project

    :param command: The django command string identifier, e.g. 'runserver'
    :param args: List of options to parse to the django management command
    :param in_background: Creates a sub-process for the command
    """
    # Ensure that django.core.management's global _command variable is set
    # before call commands, especially the once that run in the background
    get_commands()
    # Import here so other commands can run faster
    if not in_background:
        utility = ManagementUtility([os.path.basename(sys.argv[0]), command] + args)
        # This ensures that 'kalite' is printed in help menus instead of
        # 'kalitectl.py' (a part from the top most text in `kalite manage help`
        utility.prog_name = 'kalite manage'
        utility.execute()
    else:
        if os.name != "nt":
            thread = ManageThread(command, args=args, name=" ".join([command]+args))
            thread.start()
        else:
            # TODO (aron): for versions > 0.13, see if we can just have everyone spawn another process (Popen vs. ManageThread)
            Popen([sys.executable, os.path.abspath(sys.argv[0]), "manage", command] + args, creationflags=CREATE_NEW_PROCESS_GROUP)
开发者ID:JGOODYEARUCSD,项目名称:ka-lite,代码行数:25,代码来源:kalitectl.py

示例8: handle

    def handle(self,*args,**options):

        #Delete old DB
        print 'Deleting old sqlite db....'
        try:
            if settings.ON_OPENSHIFT:
                os.remove(os.path.join(os.environ['OPENSHIFT_DATA_DIR'],'mwach.db'))
            else:
                os.remove(os.path.join(settings.PROJECT_PATH,'mwach.db'))
        except OSError:
            pass

        if not os.path.isfile(JSON_DATA_FILE):
            sys.exit('JSON file %s Does Not Exist'%(JSON_DATA_FILE,))

        #Migrate new models
        print 'Migrating new db....'
        utility = ManagementUtility(['reset_db.py','migrate'])
        utility.execute()

        #Turn off Autocommit
        #transaction.set_autocommit(False)

        config.CURRENT_DATE = datetime.date.today()
        with transaction.atomic():
            create_backend()

            if options['participants'] > 0:
                load_old_participants(options)

            if options['jennifer']:
                add_jennifers()
开发者ID:nyafreddy,项目名称:mwachx,代码行数:32,代码来源:reset_db.py

示例9: update_migrations

def update_migrations():
    """
    Creates schemamigrations for localshop.
    """
    from django.core.management import ManagementUtility
    args = 'manage.py schemamigration localshop --auto'.split(' ')
    utility = ManagementUtility(args)
    utility.execute()
开发者ID:posborne,项目名称:localshop,代码行数:8,代码来源:manage.py

示例10: execute_from_command_line

def execute_from_command_line(argv=None):
    """
    A simple method that runs a ManagementUtility.
    """
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "colab.settings")

    utility = ManagementUtility(argv)
    utility.execute()
开发者ID:rafamanzo,项目名称:colab,代码行数:8,代码来源:__init__.py

示例11: _run_autocomplete

 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:2015E8007361074,项目名称:django,代码行数:8,代码来源:tests.py

示例12: _run

 def _run(coor, argv):
     global urlpatterns
     urlpatterns = patterns('',
         url('.*', coor or DjangoCoor())
     )
     os.environ['DJANGO_SETTINGS_MODULE'] = __name__
     utility = ManagementUtility(sys.argv[:1] + argv)
     utility.execute()
开发者ID:wanziforever,项目名称:statistics,代码行数:8,代码来源:coor.py

示例13: run_management_command

 def run_management_command(self, *args):
     from django.core.management import ManagementUtility
     args = ['manage.py'] + list(args)
     utility = ManagementUtility(args)
     try:
         utility.execute()
     except SystemExit:
         pass
     print('')
开发者ID:numbas,项目名称:editor,代码行数:9,代码来源:first_setup.py

示例14: test_version_is_printed_once

 def test_version_is_printed_once(self):
     args = ['manage.py', '--version']
     utility = ManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     finally:
         self.end_capture()
     expected = get_version()
     self.assertTrue(self.capture['stdout'].count(expected) == 1)
开发者ID:iluminite,项目名称:django-configglue,代码行数:10,代码来源:test_settings.py

示例15: test_update_settings

 def test_update_settings(self):
     self.assertTrue(settings.DEBUG)
     args = ['manage.py', 'settings', '--django_debug=False', 'DEBUG']
     utility = ManagementUtility(argv=args)
     self.begin_capture()
     try:
         utility.execute()
     finally:
         self.end_capture()
     self.assertTrue('False' in self.capture['stdout'])
开发者ID:iluminite,项目名称:django-configglue,代码行数:10,代码来源:test_settings.py


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