예제 #1
0
def create_game(game_dir, game_template, setting_dict):
    """
    Create a new game dir.

    Args:
        game_dir: (string)game's dir

    Returns:
        None
    """
    launcher_utils.create_game_directory(game_dir, game_template, setting_dict)

    os.chdir(game_dir)
    evennia_launcher.init_game_directory(game_dir, check_db=False)
예제 #2
0
파일: utils.py 프로젝트: kickreg/muddery
def create_game(game_dir, game_template, setting_dict):
    """
    Create a new game dir.

    Args:
        game_dir: (string)game's dir

    Returns:
        None
    """
    launcher_utils.create_game_directory(game_dir, game_template, setting_dict)

    os.chdir(game_dir)
    evennia_launcher.init_game_directory(game_dir, check_db=False)
예제 #3
0
def main():
    """
    Run the muddery main program.
    """

    # set up argument parser

    parser = ArgumentParser(description=configs.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(
        '--init',
        nargs='+',
        action='store',
        dest="init",
        metavar="game_name [template]",
        help=
        "Creates a new game directory 'game_name' at the current location (from optional template)."
    )
    parser.add_argument(
        '-l',
        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="Tests a running server by connecting N dummy players to it.")
    parser.add_argument(
        '--settings',
        nargs=1,
        action='store',
        dest='altsettings',
        default=None,
        metavar="filename.py",
        help=
        "Start evennia with alternative settings file in gamedir/server/conf/."
    )
    parser.add_argument(
        '--upgrade',
        nargs='?',
        const='',
        dest='upgrade',
        metavar="[template]",
        help="Upgrade a game directory 'game_name' to the latest version.")
    parser.add_argument('--loaddata',
                        action='store_true',
                        dest='loaddata',
                        default=False,
                        help="Load local data from the worlddata folder.")
    parser.add_argument("option",
                        nargs='?',
                        default="noop",
                        help="Operational mode: 'start', 'stop' or 'restart'.")
    parser.add_argument(
        "service",
        metavar="component",
        nargs='?',
        default="all",
        help=
        "Server component to operate on: 'server', 'portal' or 'all' (default)."
    )
    parser.epilog = "Example django-admin commands: 'migrate', 'flush', 'shell' and 'dbshell'. " \
                    "See the django documentation for more django-admin commands."

    args, unknown_args = parser.parse_known_args()

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

    # make sure we have everything
    evennia_launcher.check_main_evennia_dependencies()

    if not args:
        # show help pane
        print(configs.CMDLINE_HELP)
        sys.exit()
    elif args.init:
        # initialization of game directory
        game_name = args.init[0]
        template = None
        if len(args.init) > 1:
            template = args.init[1]

        gamedir = os.path.abspath(os.path.join(configs.CURRENT_DIR, game_name))
        utils.create_game_directory(gamedir, template)

        os.chdir(gamedir)
        evennia_launcher.init_game_directory(gamedir, check_db=False)

        # make migrations
        try:
            django_args = ["makemigrations"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError, exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        # migrate the database
        try:
            django_args = ["migrate"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)

            django_args = ["migrate"]
            django_kwargs = {"database": "worlddata"}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError, exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))
예제 #4
0
def main():
    """
    Run the muddery main program.
    """

    # set up argument parser

    parser = ArgumentParser(description=configs.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('--init', nargs='+', action='store', dest="init", metavar="game_name [template]",
                        help="Creates a new game directory 'game_name' at the current location (from optional template).")
    parser.add_argument('-l', 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="Tests a running server by connecting N dummy players to it.")
    parser.add_argument('--settings', nargs=1, action='store', dest='altsettings', default=None, metavar="filename.py",
                        help="Start evennia with alternative settings file in gamedir/server/conf/.")
    parser.add_argument('--upgrade', nargs='?', const='', dest='upgrade', metavar="[template]",
                        help="Upgrade a game directory 'game_name' to the latest version.")
    parser.add_argument("option", nargs='?', default="noop",
                        help="Operational mode: 'start', 'stop' or 'restart'.")
    parser.add_argument("service", metavar="component", nargs='?', default="all",
                        help="Server component to operate on: 'server', 'portal' or 'all' (default).")
    parser.epilog = "Example django-admin commands: 'migrate', 'flush', 'shell' and 'dbshell'. " \
                    "See the django documentation for more django-admin commands."

    args, unknown_args = parser.parse_known_args()

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

    # make sure we have everything
    evennia_launcher.check_main_evennia_dependencies()

    if not args:
        # show help pane
        print(configs.CMDLINE_HELP)
        sys.exit()
    elif args.init:
        # initialization of game directory
        game_name = args.init[0]
        template = None
        if len(args.init) > 1:
            template = args.init[1]

        gamedir = os.path.abspath(os.path.join(configs.CURRENT_DIR, game_name))
        utils.create_game_directory(gamedir, template)

        os.chdir(gamedir)
        evennia_launcher.init_game_directory(gamedir, check_db=False)

        django_args = ["makemigrations"]
        django_kwargs = {}
        try:
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError, exc:
            print(configs.ERROR_INPUT.format(traceback=exc, args=django_args, kwargs=django_kwargs))

        try:
            django_args = ["migrate"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError, exc:
            print(configs.ERROR_INPUT.format(traceback=exc, args=django_args, kwargs=django_kwargs))
예제 #5
0
def main():
    """
    Run the muddery main program.
    """

    # set up argument parser

    parser = ArgumentParser(description=configs.CMDLINE_HELP,
                            formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('--gamedir',
                        nargs=1,
                        action='store',
                        dest='altgamedir',
                        metavar="<path>",
                        help="location of gamedir (default: current location)")
    parser.add_argument(
        '--init',
        nargs='+',
        action='store',
        dest="init",
        metavar="<gamename> [template name]",
        help=
        "creates a new gamedir 'name' at current location (from optional template)."
    )
    parser.add_argument(
        '--log',
        '-l',
        action='store_true',
        dest='tail_log',
        default=False,
        help="tail the portal and server logfiles and print to stdout")
    parser.add_argument(
        '--list',
        nargs='+',
        action='store',
        dest='listsetting',
        metavar="all|<key>",
        help=("list settings, use 'all' to list all available keys"))
    parser.add_argument(
        '--settings',
        nargs=1,
        action='store',
        dest='altsettings',
        default=None,
        metavar="<path>",
        help=("start evennia with alternative settings file from\n"
              " 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\n gamedir/server/conf/settings.py"
    )
    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 server by connecting <N> dummy accounts to it")
    parser.add_argument('-v',
                        '--version',
                        action='store_true',
                        dest='show_version',
                        default=False,
                        help="show version info")
    parser.add_argument(
        '--upgrade',
        nargs='?',
        const='',
        dest='upgrade',
        metavar="[template]",
        help="Upgrade a game directory 'game_name' to the latest version.")
    parser.add_argument('--loaddata',
                        action='store_true',
                        dest='loaddata',
                        default=False,
                        help="Load local data from the worlddata folder.")

    parser.add_argument("operation",
                        nargs='?',
                        default="noop",
                        help=configs.ARG_OPTIONS)
    parser.epilog = (
        "Common Django-admin commands are shell, dbshell, test and migrate.\n"
        "See the Django documentation for more management commands.")

    args, unknown_args = parser.parse_known_args()

    # handle arguments
    option = args.operation

    # make sure we have everything
    evennia_launcher.check_main_evennia_dependencies()

    if not args:
        # show help pane
        print(configs.CMDLINE_HELP)
        sys.exit()
    elif args.init:
        # initialization of game directory
        game_name = args.init[0]
        template = None
        if len(args.init) > 1:
            template = args.init[1]

        gamedir = os.path.abspath(os.path.join(configs.CURRENT_DIR, game_name))
        utils.create_game_directory(gamedir, template)

        os.chdir(gamedir)
        evennia_launcher.GAMEDIR = gamedir
        evennia_launcher.init_game_directory(gamedir, check_db=False)

        # make migrations
        try:
            django_args = ["makemigrations", "gamedata"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError as exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        try:
            django_args = ["makemigrations", "worlddata"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError as exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        # migrate the database
        try:
            django_args = ["migrate"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)

            django_args = ["migrate", "gamedata"]
            django_kwargs = {"database": "gamedata"}
            django.core.management.call_command(*django_args, **django_kwargs)

            django_args = ["migrate", "worlddata"]
            django_kwargs = {"database": "worlddata"}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError as exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        # import worlddata
        try:
            print("Importing local data.")
            import_local_data()
        except Exception as e:
            print("Import local data error: %s" % e)

        print(
            configs.CREATED_NEW_GAMEDIR.format(gamedir=args.init[0],
                                               settings_path=os.path.join(
                                                   args.init[0],
                                                   configs.SETTINGS_PATH)))
        sys.exit()
    elif args.upgrade is not None:
        utils.check_gamedir(configs.CURRENT_DIR)

        try:
            from muddery.server.upgrader.upgrade_handler import UPGRADE_HANDLER
            template = None
            if args.upgrade:
                template = args.upgrade

            gamedir = os.path.abspath(configs.CURRENT_DIR)
            UPGRADE_HANDLER.upgrade_game(gamedir, template,
                                         configs.MUDDERY_LIB)
        except Exception as e:
            print("Upgrade failed: %s" % e)

        sys.exit()
    elif args.loaddata:
        print("Importing local data.")

        gamedir = os.path.abspath(configs.CURRENT_DIR)
        os.chdir(gamedir)
        evennia_launcher.init_game_directory(gamedir, check_db=False)

        # make migrations
        django_args = ["makemigrations", "worlddata"]
        django_kwargs = {}
        try:
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError as exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        # migrate the database
        django_args = ["migrate"]
        django_kwargs = {}
        try:
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError as exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        django_args = ["migrate", "worlddata"]
        django_kwargs = {"database": "worlddata"}
        try:
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError as exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        # load local data
        try:
            import_local_data()
            print("Import local data success.")
        except Exception as e:
            print("Import local data error: %s" % e)

        sys.exit()

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

    if args.altsettings:
        evennia_launcher.main()

    if option != "noop":
        # check current game's version
        try:
            utils.check_gamedir(configs.CURRENT_DIR)
            evennia_launcher.set_gamedir(configs.CURRENT_DIR)

            from muddery.server.upgrader.upgrade_handler import UPGRADE_HANDLER
            game_ver, game_template = utils.get_game_config(
                configs.CURRENT_DIR)
            if UPGRADE_HANDLER.can_upgrade(game_ver):
                ver_str = ".".join([str(v) for v in game_ver])
                print(configs.NEED_UPGRADE.format(version=ver_str))
                return
        except Exception as e:
            traceback.print_exc()
            print("Check upgrade error: %s" % e)
            return

        # pass-through to evennia
        evennia_launcher.main()

        if option == "start":
            # Collect static files.
            django_args = ["collectstatic"]
            django_kwargs = {"verbosity": 0, "interactive": False}
            try:
                django.core.management.call_command(*django_args,
                                                    **django_kwargs)
                print("Static file collected.")
            except django.core.management.base.CommandError as exc:
                print(
                    configs.ERROR_INPUT.format(traceback=exc,
                                               args=django_args,
                                               kwargs=django_kwargs))

            print_info()
    else:
        # no input; print muddery info
        print(configs.ABOUT_INFO)
예제 #6
0
def main():
    """
    Run the muddery main program.
    """

    # set up argument parser

    parser = ArgumentParser(description=configs.CMDLINE_HELP,
                            formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('--gamedir',
                        nargs=1,
                        action='store',
                        dest='altgamedir',
                        metavar="<path>",
                        help="location of gamedir (default: current location)")
    parser.add_argument(
        '--init',
        nargs='+',
        action='store',
        dest="init",
        metavar="<gamename> [template name]",
        help=
        "creates a new gamedir 'name' at current location (from optional template)."
    )
    parser.add_argument(
        '--log',
        '-l',
        action='store_true',
        dest='tail_log',
        default=False,
        help="tail the portal and server logfiles and print to stdout")
    parser.add_argument(
        '--list',
        nargs='+',
        action='store',
        dest='listsetting',
        metavar="all|<key>",
        help=("list settings, use 'all' to list all available keys"))
    parser.add_argument(
        '--settings',
        nargs=1,
        action='store',
        dest='altsettings',
        default=None,
        metavar="<path>",
        help=("start evennia with alternative settings file from\n"
              " 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\n gamedir/server/conf/settings.py"
    )
    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 server by connecting <N> dummy accounts to it")
    parser.add_argument('-v',
                        '--version',
                        action='store_true',
                        dest='show_version',
                        default=False,
                        help="show version info")
    parser.add_argument(
        '--upgrade',
        nargs='?',
        const='',
        dest='upgrade',
        metavar="[template]",
        help="Upgrade a game directory 'game_name' to the latest version.")
    parser.add_argument('--loaddata',
                        action='store_true',
                        dest='loaddata',
                        default=False,
                        help="Load local data from the worlddata folder.")

    parser.add_argument("operation",
                        nargs='?',
                        default="noop",
                        help=configs.ARG_OPTIONS)
    parser.epilog = (
        "Common Django-admin commands are shell, dbshell, test and migrate.\n"
        "See the Django documentation for more management commands.")

    args, unknown_args = parser.parse_known_args()

    # handle arguments
    option = args.operation

    # make sure we have everything
    evennia_launcher.check_main_evennia_dependencies()

    if not args:
        # show help pane
        print(configs.CMDLINE_HELP)
        sys.exit()
    elif args.init:
        # initialization of game directory
        game_name = args.init[0]
        template = None
        if len(args.init) > 1:
            template = args.init[1]

        gamedir = os.path.abspath(os.path.join(configs.CURRENT_DIR, game_name))
        utils.create_game_directory(gamedir, template)

        os.chdir(gamedir)
        evennia_launcher.GAMEDIR = gamedir
        evennia_launcher.init_game_directory(gamedir, check_db=False)

        # make migrations
        try:
            django_args = ["makemigrations", "worlddata"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError, exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))

        # migrate the database
        try:
            django_args = ["migrate"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)

            django_args = ["migrate", "worlddata"]
            django_kwargs = {"database": "worlddata"}
            django.core.management.call_command(*django_args, **django_kwargs)
        except django.core.management.base.CommandError, exc:
            print(
                configs.ERROR_INPUT.format(traceback=exc,
                                           args=django_args,
                                           kwargs=django_kwargs))