Ejemplo n.º 1
0
    def upgrade_game(self, game_dir, game_template, muddery_lib):
        """
        Upgrade a game.

        Args:
            game_dir: (string) the game dir to be upgraded.
            game_template: (string) the game template used to upgrade the game dir.
            muddery_lib: (string) muddery's dir
        """
        print("Upgrading game 0.0.0-0.2.0 %s." % game_dir)

        print("""
    We are very sorry that your game is too old to
    upgrade.

    If you want to upgrade your game nevertheless,
    please contact the author.""")

        raise MudderyError("Can not upgrade.")

        temp_dir = None
        try:
            # get settings
            setting_list = {
                "ALLOWED_HOSTS", "WEBSERVER_PORTS", "WEBSOCKET_CLIENT_PORT",
                "AMP_PORT", "LANGUAGE_CODE", "SECRET_KEY"
            }
            setting_dict = utils.get_settings(game_dir, setting_list)

            # create new game in temp dir
            temp_dir = utils.get_temp_dir_name(game_dir)
            utils.create_game(temp_dir, game_template, setting_dict)

            # copy old files
            # database
            utils.copy_path(game_dir, temp_dir,
                            os.path.join("server", "muddery.db3"))

            # migrations
            shutil.rmtree(os.path.join(temp_dir, "worlddata", "migrations"))
            utils.copy_path(game_dir, temp_dir,
                            os.path.join("worlddata", "migrations"))

            # make new migrations
            os.chdir(temp_dir)
            django_args = ["makemigrations"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)

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

            # copy game name
            from muddery.worlddata.data_sets import DATA_SETS
            server_name = utils.get_settings(temp_dir, ["SERVERNAME"])
            if server_name:
                kwargs = {
                    "game_name": ast.literal_eval(server_name["SERVERNAME"])
                }
                DATA_SETS.game_settings.objects.all().update(**kwargs)

            # upgrade system data
            from django.conf import settings
            custom_data_path = os.path.join(game_dir,
                                            settings.WORLD_DATA_FOLDER)
            system_data_path = os.path.join(settings.MUDDERY_DIR,
                                            settings.WORLD_DATA_FOLDER)

            for data_handler in DATA_SETS.system_data:
                data_handler.clear_model_data(system_data=False)
                try:
                    data_handler.import_from_path(custom_data_path,
                                                  system_data=False)
                except Exception as e:
                    print("Cannot import game data. %s" % e)

                data_handler.clear_model_data(system_data=True)
                try:
                    data_handler.import_from_path(system_data_path,
                                                  system_data=True)
                except Exception as e:
                    print("Cannot import game data. %s" % e)

            # set shop goods' key
            for data in DATA_SETS.shop_goods.objects.all():
                data.full_clean()
                data.save()

            # clear web dir
            shutil.rmtree(os.path.join(game_dir, "web"))

            # copy temp dir to game dir
            utils.copy_tree(temp_dir, game_dir)

        finally:
            if temp_dir:
                # remove temp dir
                shutil.rmtree(temp_dir)
Ejemplo n.º 2
0
    def upgrade_game(self, game_dir, game_template):
        """
        Upgrade a game.

        Args:
            game_dir: (string) the game dir to be upgraded.
            game_template: (string) the game template used to upgrade the game dir.
        """
        print("Upgrading game %s." % game_dir)

        temp_dir = None
        try:
            # Move game dir to temp dir.
            temp_dir = utils.to_temp_dir(game_dir)

            # get settings
            setting_list = {
                "ALLOWED_HOSTS", "WEBSERVER_PORTS", "WEBSOCKET_CLIENT_PORT",
                "AMP_PORT", "LANGUAGE_CODE", "SECRET_KEY"
            }
            setting_dict = utils.get_settings(temp_dir, setting_list)

            # create new game
            utils.create_game(game_dir, game_template, setting_dict)

            # copy old files
            # database
            utils.copy_path(temp_dir, game_dir,
                            os.path.join("server", "muddery.db3"))

            # migrations
            utils.copy_path(temp_dir, game_dir,
                            os.path.join("worlddata", "migrations"))

            # web
            utils.copy_path(temp_dir, game_dir, "web")

            # make new migrations
            os.chdir(game_dir)
            django_args = ["makemigrations"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)

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

            # copy game name
            from muddery.worlddata.data_sets import DATA_SETS
            server_name = utils.get_settings(temp_dir, ["SERVERNAME"])
            if server_name:
                kwargs = {
                    "game_name": ast.literal_eval(server_name["SERVERNAME"])
                }
                DATA_SETS.game_settings.objects.all().update(**kwargs)

            # upgrade system data
            from django.conf import settings
            custom_data_path = os.path.join(game_dir,
                                            settings.WORLD_DATA_FOLDER)
            system_data_path = os.path.join(settings.MUDDERY_DIR,
                                            settings.WORLD_DATA_FOLDER)

            for data_handler in DATA_SETS.system_data:
                data_handler.clear_model_data(system_data=False)
                try:
                    data_handler.import_from_path(custom_data_path,
                                                  system_data=False)
                except Exception, e:
                    print("Cannot import game data. %s" % e)

                data_handler.clear_model_data(system_data=True)
                try:
                    data_handler.import_from_path(system_data_path,
                                                  system_data=True)
                except Exception, e:
                    print("Cannot import game data. %s" % e)
Ejemplo n.º 3
0
    def upgrade_game(self, game_dir, game_template, muddery_lib):
        """
        Upgrade a game.

        Args:
            game_dir: (string) the game dir to be upgraded.
            game_template: (string) the game template used to upgrade the game dir.
            muddery_lib: (string) muddery's dir
        """
        print("Upgrading game 0.0.0-0.2.0 %s." % game_dir)

        temp_dir = None
        try:
            # get settings
            setting_list = {"ALLOWED_HOSTS",
                            "WEBSERVER_PORTS",
                            "WEBSOCKET_CLIENT_PORT",
                            "AMP_PORT",
                            "LANGUAGE_CODE",
                            "SECRET_KEY"}
            setting_dict = utils.get_settings(game_dir, setting_list)

            # create new game in temp dir
            temp_dir = utils.get_temp_dir_name(game_dir)
            utils.create_game(temp_dir, game_template, setting_dict)

            # copy old files
            # database
            utils.copy_path(game_dir, temp_dir, os.path.join("server", "muddery.db3"))

            # migrations
            shutil.rmtree(os.path.join(temp_dir, "worlddata", "migrations"))
            utils.copy_path(game_dir, temp_dir, os.path.join("worlddata", "migrations"))

            # make new migrations
            os.chdir(temp_dir)
            django_args = ["makemigrations"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)

            django_args = ["migrate"]
            django_kwargs = {}
            django.core.management.call_command(*django_args, **django_kwargs)
            
            # copy game name
            from muddery.worlddata.data_sets import DATA_SETS
            server_name = utils.get_settings(temp_dir, ["SERVERNAME"])
            if server_name:
                kwargs = {"game_name": ast.literal_eval(server_name["SERVERNAME"])}
                DATA_SETS.game_settings.objects.all().update(**kwargs)

            # upgrade system data
            from django.conf import settings
            custom_data_path = os.path.join(game_dir, settings.WORLD_DATA_FOLDER)
            system_data_path = os.path.join(settings.MUDDERY_DIR, settings.WORLD_DATA_FOLDER)

            for data_handler in DATA_SETS.system_data:
                data_handler.clear_model_data(system_data=False)
                try:
                    data_handler.import_from_path(custom_data_path, system_data=False)
                except Exception, e:
                    print("Cannot import game data. %s" % e)

                data_handler.clear_model_data(system_data=True)
                try:
                    data_handler.import_from_path(system_data_path, system_data=True)
                except Exception, e:
                    print("Cannot import game data. %s" % e)