Python django.core.management.ManagementUtility() Examples
The following are 8
code examples of django.core.management.ManagementUtility().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.core.management
, or try the search function
.
Example #1
Source File: longclaw.py From longclaw with MIT License | 5 votes |
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))
Example #2
Source File: ra.py From django-ra-erp with GNU Affero General Public License v3.0 | 5 votes |
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
Example #3
Source File: wagtail.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #4
Source File: base.py From django-ca with GNU General Public License v3.0 | 5 votes |
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()
Example #5
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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())
Example #6
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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')
Example #7
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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())
Example #8
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
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')