def unzip_resources_all(fp): """ Import all resource files from a zip file. """ media_dir = settings.MEDIA_ROOT if not os.path.exists(media_dir): os.makedirs(media_dir) temp_path = tempfile.mkdtemp() try: archive = zipfile.ZipFile(fp, 'r') archive.extractall(temp_path) source_path = temp_path # if the zip file contains a root dir file_list = os.listdir(temp_path) if len(file_list) == 1: path = os.path.join(temp_path, file_list[0]) if os.path.isdir(path): source_path = path copy_tree(source_path, media_dir) finally: shutil.rmtree(temp_path)
def unzip_resources_all(fp): """ Import all resource files from a zip file. """ media_dir = os.path.join(settings.MEDIA_ROOT, settings.IMAGE_PATH) if not os.path.exists(media_dir): os.makedirs(media_dir) temp_path = tempfile.mkdtemp() try: archive = zipfile.ZipFile(fp, 'r') archive.extractall(temp_path) source_path = temp_path # if the zip file contains a root dir file_list = os.listdir(temp_path) if len(file_list) == 1: path = os.path.join(temp_path, file_list[0]) if os.path.isdir(path): source_path = path copy_tree(source_path, media_dir) finally: shutil.rmtree(temp_path)
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 from version 0.2.9 %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.") # copy full webclient default_template = os.path.join(configs.MUDDERY_LIB, configs.TEMPLATE_DIR) muddery_web = os.path.join(configs.MUDDERY_LIB, "web", "webclient") default_web = os.path.join(default_template, "web", "webclient_overrides") dest_web = os.path.join(game_dir, "web", "webclient_full") os.mkdir(dest_web) copy_tree(os.path.join(muddery_web, "webclient"), os.path.join(dest_web, "webclient")) shutil.copy2(os.path.join(muddery_web, "package.json"), os.path.join(dest_web, "package.json")) shutil.copy2(os.path.join(muddery_web, "webpack.config.js"), os.path.join(dest_web, "webpack.config.js")) copy_tree(os.path.join(default_web, "webclient"), os.path.join(dest_web, "webclient")) if game_template: game_template_dir = os.path.join(configs.MUDDERY_TEMPLATE, game_template) # copy webclient utils.copy_path( game_template_dir, game_dir, os.path.join("web", "webclient_overrides", "webclient")) # create dist folder os.mkdir( os.path.join(game_dir, "web", "webclient_overrides", "dist")) # copy full webclient template_web = os.path.join(game_template_dir, "web", "webclient_overrides") copy_tree(os.path.join(template_web, "webclient"), os.path.join(dest_web, "webclient"))
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 from version 0.2.9 %s." % game_dir) # copy full webclient default_template = os.path.join(configs.MUDDERY_LIB, configs.TEMPLATE_DIR) muddery_web = os.path.join(configs.MUDDERY_LIB, "web", "webclient") default_web = os.path.join(default_template, "web", "webclient_overrides") dest_web = os.path.join(game_dir, "web", "webclient_full") os.mkdir(dest_web) copy_tree(os.path.join(muddery_web, "webclient"), os.path.join(dest_web, "webclient")) shutil.copy2(os.path.join(muddery_web, "package.json"), os.path.join(dest_web, "package.json")) shutil.copy2(os.path.join(muddery_web, "webpack.config.js"), os.path.join(dest_web, "webpack.config.js")) copy_tree(os.path.join(default_web, "webclient"), os.path.join(dest_web, "webclient")) if game_template: game_template_dir = os.path.join(configs.MUDDERY_TEMPLATE, game_template) # copy webclient utils.copy_path( game_template_dir, game_dir, os.path.join("web", "webclient_overrides", "webclient")) # create dist folder os.mkdir( os.path.join(game_dir, "web", "webclient_overrides", "dist")) # copy full webclient template_web = os.path.join(game_template_dir, "web", "webclient_overrides") copy_tree(os.path.join(template_web, "webclient"), os.path.join(dest_web, "webclient"))
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 from version 0.2.9 %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.") # copy full webclient default_template = os.path.join(configs.MUDDERY_LIB, configs.TEMPLATE_DIR) muddery_web = os.path.join(configs.MUDDERY_LIB, "web", "webclient") default_web = os.path.join(default_template, "web", "webclient_overrides") dest_web = os.path.join(game_dir, "web", "webclient_full") os.mkdir(dest_web) copy_tree(os.path.join(muddery_web, "webclient"), os.path.join(dest_web, "webclient")) shutil.copy2(os.path.join(muddery_web, "package.json"), os.path.join(dest_web, "package.json")) shutil.copy2(os.path.join(muddery_web, "webpack.config.js"), os.path.join(dest_web, "webpack.config.js")) copy_tree(os.path.join(default_web, "webclient"), os.path.join(dest_web, "webclient")) if game_template: game_template_dir = os.path.join(configs.MUDDERY_TEMPLATE, game_template) # copy webclient utils.copy_path(game_template_dir, game_dir, os.path.join("web", "webclient_overrides", "webclient")) # create dist folder os.mkdir(os.path.join(game_dir, "web", "webclient_overrides", "dist")) # copy full webclient template_web = os.path.join(game_template_dir, "web", "webclient_overrides") copy_tree(os.path.join(template_web, "webclient"), os.path.join(dest_web, "webclient"))