def archive_files(self, src_file_list, dest_pak_path): """ create a pak file with directory preserved Arguments src_file_list -- list of pairs of absolute paths to files to pack and the portion of the path that represents what to use as the root of the file so that the pack has the correct relative folder structure dest_pak_path -- absolute path and file name of the pak file to create """ # create a temporary folder temp_dir = tempfile.mkdtemp() vprint("Create temp dir: " + temp_dir) # copy the files to the temporary folder for file, src_file_root in src_file_list: file = os.path.normpath(file) file = os.path.normcase(file) vprint("\n\tProcessing " + file) # verify the file starts with the root src_file_root = os.path.normpath(src_file_root) src_file_root = os.path.normcase(src_file_root) vprint("\tSource file root is " + src_file_root) if not file.startswith(src_file_root): print( "File doesn't have correct root. Root is: {} and file path is: {}" .format(src_file_root, file)) else: relative_path = ensure_posix_path(file[len(src_file_root):]) # Be sure we aren't starting with a file separator or the join below will fail if len(relative_path) and relative_path[0] == posixpath.sep: relative_path = relative_path[1:] vprint("\tRelative path " + relative_path) temp_path = os.path.join(temp_dir, relative_path) vprint("\tTemp path " + temp_path) if not os.path.exists(os.path.dirname(temp_path)): try: os.makedirs(os.path.dirname(temp_path)) except OSError as exc: # guard against race condition if exc.errno != errno.EEXIST: raise shutil.copy(file, temp_path) # clear read only flags in case this came from source control environment so the temp folder # can be removed when done os.chmod( temp_path, stat.S_IWUSR | stat.S_IRUSR | stat.S_IWGRP | stat.S_IRGRP | stat.S_IWOTH | stat.S_IROTH) # create a pak archive from the files in the temporary folder self.archive_folder(temp_dir, dest_pak_path) # delete the temporary files and folder shutil.rmtree(temp_dir)
def get_pak_game_folder(game_folder_name): return ensure_posix_path(os.path.join(game_folder_name, get_pak_folder()))
def get_table_backup_folder(game_folder_name): return ensure_posix_path( os.path.join(game_folder_name, get_backup_folder()))
def get_private_certificate_game_folder(game_folder_name): return ensure_posix_path( os.path.join(game_folder_name, get_private_certificate_folder()))