# Buggy code
def create_project(parser, options, args):
    # Validate args
    if len(args) < 2:
        parser.error("Please specify a name for your wagtail installation")
    elif len(args) > 2:
        parser.error("Too many arguments")

    project_name = args[1]

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

    # Make sure directory does not already exist
    if os.path.exists(project_name):
        print(
            "A directory called %(project_name)s already exists. \
            Please choose another name for your wagtail project or remove the existing directory."
            % {"project_name": project_name}
        )
        sys.exit(errno.EEXIST)

    print(
        "Creating a wagtail project called %(project_name)s"
        % {"project_name": project_name}
    )

    # 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
    result = subprocess.call(
        [
            "django-admin.py",
            "startproject",
            "--template=" + template_path,
            "--name=Vagrantfile",
            "--ext=html,rst",
            project_name,
        ]
    )

    if result == 0:
        print("Success! %(project_name)s is created" % {"project_name": project_name})


# Traceback (WindowsError)
$ wagtail start wagtailtest
Creating a wagtail project called wagtailtest
Traceback (most recent call last):
File "d:\VirtualEnvs\wagtail_env\Scripts\wagtail-script.py", line 9, in <module>
load_entry_point('wagtail==0.6', 'console_scripts', 'wagtail')()
File "d:\VirtualEnvs\wagtail_env\lib\site-packages\wagtail\bin\wagtail.py", line 75, in main
COMMANDS[command](parser, options, args)
File "d:\VirtualEnvs\wagtail_env\lib\site-packages\wagtail\bin\wagtail.py", line 51, in create_project
project_name
File "C:\Python27\Lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\Lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\Lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application

# Fixed code
def create_project(parser, options, args):
    # Validate args
    if len(args) < 2:
        parser.error("Please specify a name for your wagtail installation")
    elif len(args) > 2:
        parser.error("Too many arguments")

    project_name = args[1]

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

    # Make sure directory does not already exist
    if os.path.exists(project_name):
        print(
            "A directory called %(project_name)s already exists. \
            Please choose another name for your wagtail project or remove the existing directory."
            % {"project_name": project_name}
        )
        sys.exit(errno.EEXIST)

    print(
        "Creating a wagtail project called %(project_name)s"
        % {"project_name": project_name}
    )

    # 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 = ManagementUtility(
        [
            "django-admin.py",
            "startproject",
            "--template=" + template_path,
            "--name=Vagrantfile",
            "--ext=html,rst",
            project_name,
        ]
    )
    utility.execute()

    print("Success! %(project_name)s is created" % {"project_name": project_name})