# Buggy code
def main():
    """
    Run the evennia launcher main program.

    """

    # set up argument parser

    parser = ArgumentParser(description=CMDLINE_HELP)
    parser.add_argument(
        "-v",
        "--version",
        action="store_true",
        dest="show_version",
        default=False,
        help="Show version info.",
    )
    parser.add_argument(
        "-i",
        "--interactive",
        action="store_true",
        dest="interactive",
        default=False,
        help="Start given processes in interactive mode.",
    )
    parser.add_argument(
        "-l",
        "--log",
        action="store_true",
        dest="logserver",
        default=False,
        help="Log Server data to log file.",
    )
    parser.add_argument(
        "--init",
        action="store",
        dest="init",
        metavar="name",
        help="Creates a new game directory 'name' at the current location.",
    )
    parser.add_argument(
        "--list",
        nargs="+",
        action="store",
        dest="listsetting",
        metavar="key",
        help=("List values for server settings. Use 'all' to list all available keys."),
    )
    parser.add_argument(
        "--profiler",
        action="store_true",
        dest="profiler",
        default=False,
        help="Start given server component under the Python profiler.",
    )
    parser.add_argument(
        "--dummyrunner",
        nargs=1,
        action="store",
        dest="dummyrunner",
        metavar="N",
        help="Test a running server by connecting N dummy accounts to it.",
    )
    parser.add_argument(
        "--settings",
        nargs=1,
        action="store",
        dest="altsettings",
        default=None,
        metavar="filename.py",
        help=(
            "Start evennia with alternative settings file from "
            "gamedir/server/conf/. (default is settings.py)"
        ),
    )
    parser.add_argument(
        "--initsettings",
        action="store_true",
        dest="initsettings",
        default=False,
        help="Create a new, empty settings file as gamedir/server/conf/settings.py.",
    )
    parser.add_argument(
        "--external-runner",
        action="store_true",
        dest="doexit",
        default=False,
        help="Handle server restart with an external process manager.",
    )
    parser.add_argument(
        "operation",
        nargs="?",
        default="noop",
        help="Operation to perform: 'start', 'stop', 'reload' or 'menu'.",
    )
    parser.add_argument(
        "service",
        metavar="component",
        nargs="?",
        default="all",
        help=(
            "Which component to operate on: "
            "'server', 'portal' or 'all' (default if not set)."
        ),
    )
    parser.epilog = (
        "Common usage: evennia start|stop|reload. Django-admin database commands:"
        "evennia migration|flush|shell|dbshell (see the django documentation for more django-admin commands.)"
    )

    args, unknown_args = parser.parse_known_args()

    # handle arguments
    option, service = args.operation, args.service

    # make sure we have everything
    check_main_evennia_dependencies()

    if not args:
        # show help pane
        print(CMDLINE_HELP)
        sys.exit()
    elif args.init:
        # initialization of game directory
        create_game_directory(args.init)
        print(
            CREATED_NEW_GAMEDIR.format(
                gamedir=args.init, settings_path=os.path.join(args.init, SETTINGS_PATH)
            )
        )
        sys.exit()

    if args.show_version:
        # show the version info
        print(show_version_info(option == "help"))
        sys.exit()

    if args.altsettings:
        # use alternative settings file
        sfile = args.altsettings[0]
        global SETTINGSFILE, SETTINGS_DOTPATH, ENFORCED_SETTING
        SETTINGSFILE = sfile
        ENFORCED_SETTING = True
        SETTINGS_DOTPATH = "server.conf.%s" % sfile.rstrip(".py")
        print("Using settings file '%s' (%s)." % (SETTINGSFILE, SETTINGS_DOTPATH))

    if args.initsettings:
        # create new settings file
        global GAMEDIR
        GAMEDIR = os.getcwd()
        try:
            create_settings_file(init=False)
            print(RECREATED_SETTINGS)
        except IOError:
            print(ERROR_INITSETTINGS)
        sys.exit()

    if args.dummyrunner:
        # launch the dummy runner
        init_game_directory(CURRENT_DIR, check_db=True)
        run_dummyrunner(args.dummyrunner[0])
    elif args.listsetting:
        # display all current server settings
        init_game_directory(CURRENT_DIR, check_db=False)
        list_settings(args.listsetting)
    elif option == "menu":
        # launch menu for operation
        init_game_directory(CURRENT_DIR, check_db=True)
        run_menu()
    elif option in ("start", "reload", "stop"):
        # operate the server directly
        init_game_directory(CURRENT_DIR, check_db=True)
        server_operation(
            option,
            service,
            args.interactive,
            args.profiler,
            args.logserver,
            doexit=args.doexit,
        )
    elif option != "noop":
        # pass-through to django manager
        check_db = False
        if option in ("runserver", "testserver"):
            print(WARNING_RUNSERVER)
        if option == "shell":
            # to use the shell we need to initialize it first,
            # and this only works if the database is set up
            check_db = True
        if option == "test":
            global TEST_MODE
            TEST_MODE = True
        init_game_directory(CURRENT_DIR, check_db=check_db)

        args = [option]
        kwargs = {}
        if service not in ("all", "server", "portal"):
            args.append(service)
        if unknown_args:
            for arg in unknown_args:
                if arg.startswith("--"):
                    print("arg:", arg)
                    if "=" in arg:
                        arg, value = [p.strip() for p in arg.split("=", 1)]
                    else:
                        value = True
                    kwargs[arg.lstrip("--")] = value
                else:
                    args.append(arg)
        try:
            django.core.management.call_command(*args, **kwargs)
        except django.core.management.base.CommandError as exc:
            args = ", ".join(args)
            kwargs = ", ".join(["--%s" % kw for kw in kwargs])
            print(ERROR_INPUT.format(traceback=exc, args=args, kwargs=kwargs))
    else:
        # no input; print evennia info
        print(ABOUT_INFO)


# Traceback (TypeError)
(arx) c:\arx\arx>evennia check
Traceback (most recent call last):
File "c:\arx\Scripts\evennia_launcher.py", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "C:\arx\evennia\bin\windows\evennia_launcher.py", line 16, in <module>
main()
File "c:\arx\evennia\evennia\server\evennia_launcher.py", line 1333, in main
django.core.management.call_command(*args, **kwargs)
File "c:\arx\Lib\site-packages\django\core\management\__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "c:\arx\Lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "c:\arx\Lib\site-packages\django\core\management\commands\check.py", line 51, in handle
include_deployment_checks=include_deployment_checks,
File "c:\arx\Lib\site-packages\django\core\management\base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "c:\arx\Lib\site-packages\django\core\checks\registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "c:\arx\Lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "c:\arx\Lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "c:\arx\Lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "c:\arx\Lib\site-packages\django\core\urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "c:\arx\Lib\site-packages\django\utils\functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "c:\arx\Lib\site-packages\django\core\urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "c:\arx\arx\web\urls.py", line 43, in <module>
namespace='help_topics', app_name='help_topics')),
File "c:\arx\Lib\site-packages\django\conf\urls\__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "C:\Python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "c:\arx\arx\web\help_topics\urls.py", line 10, in <module>
from .views import (topic, list_commands, list_topics, list_recipes,
File "c:\arx\arx\web\help_topics\views.py", line 8, in <module>
from commands.default_cmdsets import PlayerCmdSet, CharacterCmdSet
File "c:\arx\arx\commands\default_cmdsets.py", line 17, in <module>
from evennia.commands.default import cmdset_character, cmdset_player, cmdset_session, cmdset_unloggedin
File "c:\arx\evennia\evennia\commands\default\cmdset_character.py", line 8, in <module>
from evennia.commands.default import general, help, admin, system
File "c:\arx\evennia\evennia\commands\default\help.py", line 14, in <module>
from evennia.utils import create, evmore
File "c:\arx\evennia\evennia\utils\evmore.py", line 51, in <module>
class CmdMore(Command):
TypeError: Error when calling the metaclass bases
cannot create 'NoneType' instances

# Fixed code
def main():
    """
    Run the evennia launcher main program.

    """

    # set up argument parser

    parser = ArgumentParser(description=CMDLINE_HELP)
    parser.add_argument(
        "-v",
        "--version",
        action="store_true",
        dest="show_version",
        default=False,
        help="Show version info.",
    )
    parser.add_argument(
        "-i",
        "--interactive",
        action="store_true",
        dest="interactive",
        default=False,
        help="Start given processes in interactive mode.",
    )
    parser.add_argument(
        "-l",
        "--log",
        action="store_true",
        dest="logserver",
        default=False,
        help="Log Server data to log file.",
    )
    parser.add_argument(
        "--init",
        action="store",
        dest="init",
        metavar="name",
        help="Creates a new game directory 'name' at the current location.",
    )
    parser.add_argument(
        "--list",
        nargs="+",
        action="store",
        dest="listsetting",
        metavar="key",
        help=("List values for server settings. Use 'all' to list all available keys."),
    )
    parser.add_argument(
        "--profiler",
        action="store_true",
        dest="profiler",
        default=False,
        help="Start given server component under the Python profiler.",
    )
    parser.add_argument(
        "--dummyrunner",
        nargs=1,
        action="store",
        dest="dummyrunner",
        metavar="N",
        help="Test a running server by connecting N dummy accounts to it.",
    )
    parser.add_argument(
        "--settings",
        nargs=1,
        action="store",
        dest="altsettings",
        default=None,
        metavar="filename.py",
        help=(
            "Start evennia with alternative settings file from "
            "gamedir/server/conf/. (default is settings.py)"
        ),
    )
    parser.add_argument(
        "--initsettings",
        action="store_true",
        dest="initsettings",
        default=False,
        help="Create a new, empty settings file as gamedir/server/conf/settings.py.",
    )
    parser.add_argument(
        "--external-runner",
        action="store_true",
        dest="doexit",
        default=False,
        help="Handle server restart with an external process manager.",
    )
    parser.add_argument(
        "operation",
        nargs="?",
        default="noop",
        help="Operation to perform: 'start', 'stop', 'reload' or 'menu'.",
    )
    parser.add_argument(
        "service",
        metavar="component",
        nargs="?",
        default="all",
        help=(
            "Which component to operate on: "
            "'server', 'portal' or 'all' (default if not set)."
        ),
    )
    parser.epilog = (
        "Common usage: evennia start|stop|reload. Django-admin database commands:"
        "evennia migration|flush|shell|dbshell (see the django documentation for more django-admin commands.)"
    )

    args, unknown_args = parser.parse_known_args()

    # handle arguments
    option, service = args.operation, args.service

    # make sure we have everything
    check_main_evennia_dependencies()

    if not args:
        # show help pane
        print(CMDLINE_HELP)
        sys.exit()
    elif args.init:
        # initialization of game directory
        create_game_directory(args.init)
        print(
            CREATED_NEW_GAMEDIR.format(
                gamedir=args.init, settings_path=os.path.join(args.init, SETTINGS_PATH)
            )
        )
        sys.exit()

    if args.show_version:
        # show the version info
        print(show_version_info(option == "help"))
        sys.exit()

    if args.altsettings:
        # use alternative settings file
        sfile = args.altsettings[0]
        global SETTINGSFILE, SETTINGS_DOTPATH, ENFORCED_SETTING
        SETTINGSFILE = sfile
        ENFORCED_SETTING = True
        SETTINGS_DOTPATH = "server.conf.%s" % sfile.rstrip(".py")
        print("Using settings file '%s' (%s)." % (SETTINGSFILE, SETTINGS_DOTPATH))

    if args.initsettings:
        # create new settings file
        global GAMEDIR
        GAMEDIR = os.getcwd()
        try:
            create_settings_file(init=False)
            print(RECREATED_SETTINGS)
        except IOError:
            print(ERROR_INITSETTINGS)
        sys.exit()

    if args.dummyrunner:
        # launch the dummy runner
        init_game_directory(CURRENT_DIR, check_db=True)
        run_dummyrunner(args.dummyrunner[0])
    elif args.listsetting:
        # display all current server settings
        init_game_directory(CURRENT_DIR, check_db=False)
        list_settings(args.listsetting)
    elif option == "menu":
        # launch menu for operation
        init_game_directory(CURRENT_DIR, check_db=True)
        run_menu()
    elif option in ("start", "reload", "stop"):
        # operate the server directly
        init_game_directory(CURRENT_DIR, check_db=True)
        server_operation(
            option,
            service,
            args.interactive,
            args.profiler,
            args.logserver,
            doexit=args.doexit,
        )
    elif option != "noop":
        # pass-through to django manager
        check_db = False
        if option in ("runserver", "testserver"):
            print(WARNING_RUNSERVER)
        if option in ("shell", "check"):
            # some django commands requires the database to exist,
            # or evennia._init to have run before they work right.
            check_db = True
        if option == "test":
            global TEST_MODE
            TEST_MODE = True
        init_game_directory(CURRENT_DIR, check_db=check_db)

        args = [option]
        kwargs = {}
        if service not in ("all", "server", "portal"):
            args.append(service)
        if unknown_args:
            for arg in unknown_args:
                if arg.startswith("--"):
                    print("arg:", arg)
                    if "=" in arg:
                        arg, value = [p.strip() for p in arg.split("=", 1)]
                    else:
                        value = True
                    kwargs[arg.lstrip("--")] = value
                else:
                    args.append(arg)
        try:
            django.core.management.call_command(*args, **kwargs)
        except django.core.management.base.CommandError as exc:
            args = ", ".join(args)
            kwargs = ", ".join(["--%s" % kw for kw in kwargs])
            print(ERROR_INPUT.format(traceback=exc, args=args, kwargs=kwargs))
    else:
        # no input; print evennia info
        print(ABOUT_INFO)