Exemple #1
0
 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")
     with captured_stderr() as stderr, self.assertRaises(SystemExit):
         management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
     self.assertIn("CommandError", stderr.getvalue())
 def handlenoargs(self):
     old_stderr = sys.stderr
     sys.stderr = err = StringIO()
     try:
         with self.assertRaises(SystemExit):
             management.ManagementUtility(['hue', 'ldaptest',
                                           '-i']).execute()
     finally:
         sys.stderr = old_stderr
     self.assertIn("no such option", err.getvalue())
 def runcommand(self):
     old_stdout = sys.stdout
     sys.stdout = out = StringIO()
     try:
         with self.assertRaises(SystemExit):
             management.ManagementUtility(['hue', 'ldaptest']).execute()
     finally:
         sys.stdout = old_stdout
     self.assertIn(
         "Could not find LDAP_URL server in hue.ini required for authentication",
         out.getvalue())
Exemple #4
0
 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")
     old_stderr = sys.stderr
     sys.stderr = err = StringIO()
     try:
         with self.assertRaises(SystemExit):
             management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
     finally:
         sys.stderr = old_stderr
     self.assertIn("CommandError", err.getvalue())
Exemple #5
0
 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) as cm:
         management.call_command('dance', example="raise")
     self.assertEqual(cm.exception.returncode, 3)
     dance.Command.requires_system_checks = []
     try:
         with captured_stderr() as stderr, self.assertRaises(SystemExit) as cm:
             management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
         self.assertEqual(cm.exception.code, 3)
     finally:
         dance.Command.requires_system_checks = '__all__'
     self.assertIn("CommandError", stderr.getvalue())
Exemple #6
0
def manage(args):
    """Run native Django management commands under djboss."""

    from django.core import management as mgmt

    OldOptionParser = mgmt.LaxOptionParser

    class LaxOptionParser(mgmt.LaxOptionParser):
        def __init__(self, *args, **kwargs):
            kwargs['prog'] = 'djboss manage'
            OldOptionParser.__init__(self, *args, **kwargs)

    mgmt.LaxOptionParser = LaxOptionParser

    utility = mgmt.ManagementUtility(['djboss manage'] + args.args)
    utility.prog_name = 'djboss manage'
    utility.execute()
Exemple #7
0
def manage(options):
    """
    Run Django management commands.
    
    The ``manage`` task allows you to run any Django management command as if
    it were a paver task. To use it, instead of running ``python manage.py``
    just use ``paver manage`` instead. For example::
        
        paver manage syncdb
        paver manage dumpdata myappname
        paver manage runserver
    
    Et cetera.
    """

    utility = mgmt.ManagementUtility(['paver manage'] + options.args)
    # This is again so that the name of the program shows up as the whole
    #`paver manage` instead of just `paver`.
    utility.prog_name = 'paver manage'
    utility.execute()
Exemple #8
0
def main():
    if len(sys.argv) != 2:
        print("Usage: %s FILE" % sys.argv[0], file=sys.stderr)
        exit(1)

    profile_file = sys.argv[1]
    profile_data = get_profile_data(profile_file, profile_file)

    urlpatterns = (
        url(r"^$",
            static.serve, {'path': "standalone.html", 'insecure': True}),
        url(r"^api/log/[a-z0-9]+/",
            lambda request: http.JsonResponse(profile_data))
    )
    base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    sys.path.append(base_dir)
    configure(base_dir, urlpatterns)

    host, port = "localhost", 8000
    webbrowser.open("http://%s:%d/#/%s" % (host, port, profile_data['checksum']))
    django_cmd = ["runserver", "--noreload", "%s:%d" % (host, port)]
    management.ManagementUtility([sys.argv[0]] + django_cmd).execute()
Exemple #9
0
from django.core import management

def main(settings_file):
    try:
        mod = __import__(settings_file)
        components = settings_file.split('.')
        for comp in components[1:]:
            mod = getattr(mod, comp)

    except ImportError, e:
        import sys
        sys.stderr.write("Error loading the settings module '%s': %s"
                            % (settings_file, e))
        return sys.exit(1)

    management.setup_environ(mod, settings_file)
    utility = management.ManagementUtility()
    utility.execute()
def command_execute(cmd):
    from django.core import management

    sys.argv = ["spring"] + cmd.split(" ")
    return management.ManagementUtility(sys.argv).execute()
def _create_project(name: str):
    management.ManagementUtility(['manage.py', 'startproject', name]).execute()
    PrettyPrint.msg_blue(
        'The Django project "{}" was successfully created'.format(name))