def copydir(fs1, fs2, create_destination=True, ignore_errors=False, chunk_size=64*1024): """Copies contents of a directory from one filesystem to another. :param fs1: Source filesystem, or a tuple of (<filesystem>, <directory path>) :param fs2: Destination filesystem, or a tuple of (<filesystem>, <directory path>) :param create_destination: If True, the destination will be created if it doesn't exist :param ignore_errors: If True, exceptions from file moves are ignored :param chunk_size: Size of chunks to move if a simple copy is used """ if isinstance(fs1, tuple): fs1, dir1 = fs1 fs1 = fs1.opendir(dir1) if isinstance(fs2, tuple): fs2, dir2 = fs2 if create_destination: fs2.makedir(dir2, allow_recreate=True, recursive=True) fs2 = fs2.opendir(dir2) mount_fs = MountFS(auto_close=False) mount_fs.mount('src', fs1) mount_fs.mount('dst', fs2) mount_fs.copydir('src', 'dst', overwrite=True, ignore_errors=ignore_errors, chunk_size=chunk_size)
def copydir(fs1, fs2, create_destination=True, ignore_errors=False, chunk_size=64 * 1024): """Copies contents of a directory from one filesystem to another. :param fs1: Source filesystem, or a tuple of (<filesystem>, <directory path>) :param fs2: Destination filesystem, or a tuple of (<filesystem>, <directory path>) :param create_destination: If True, the destination will be created if it doesn't exist :param ignore_errors: If True, exceptions from file moves are ignored :param chunk_size: Size of chunks to move if a simple copy is used """ if isinstance(fs1, tuple): fs1, dir1 = fs1 fs1 = fs1.opendir(dir1) if isinstance(fs2, tuple): fs2, dir2 = fs2 if create_destination: fs2.makedir(dir2, allow_recreate=True, recursive=True) fs2 = fs2.opendir(dir2) mount_fs = MountFS(auto_close=False) mount_fs.mount('src', fs1) mount_fs.mount('dst', fs2) mount_fs.copydir('src', 'dst', overwrite=True, ignore_errors=ignore_errors, chunk_size=chunk_size)
def main(): parser = argparse.ArgumentParser(description='SLF Unpacker') parser.add_argument('slf_file', help="path to the SLF file") parser.add_argument( '-o', '--output-folder', default=None, help="folder for extracted files. By default, files extracted alongside the slf file in a subdirectory. For example, content of foo/bar/maps.slf is extracted into folder foo/bar/maps" ) parser.add_argument( '-v', '--verbose', action='store_true', default=False, help="be verbose, e.g. print names of the extracted files" ) args = parser.parse_args() slf_file = args.slf_file slf_file = os.path.expanduser(os.path.expandvars(slf_file)) slf_file = os.path.normpath(os.path.abspath(slf_file)) if not os.path.exists(slf_file): print("Error: '{}' is not found".format(args.slf_file), file=sys.stderr) exit(1) output_folder = args.output_folder if output_folder is None: output_folder = os.path.join(os.path.dirname(slf_file), os.path.splitext(os.path.basename(slf_file))[0]) output_folder = os.path.expanduser(os.path.expandvars(output_folder)) output_folder = os.path.normpath(os.path.abspath(output_folder)) if not os.path.exists(output_folder): os.mkdir(output_folder) if args.verbose: print("Input file: {}".format(slf_file)) print("Output folder: {}".format(output_folder)) slf_fs = SlfFS(slf_file) out_fs = OSFS(output_folder) if args.verbose: print("Extracting Files:") slf_fs.printtree() combined_fs = MountFS() combined_fs.mountdir('slf', slf_fs) combined_fs.mountdir('out', out_fs) combined_fs.copydir('/slf', '/out', overwrite=True) if args.verbose: print("Done")
def movedir(fs1, fs2, create_destination=True, ignore_errors=False, chunk_size=64 * 1024): """Moves contents of a directory from one filesystem to another. :param fs1: A tuple of (<filesystem>, <directory path>) :param fs2: Destination filesystem, or a tuple of (<filesystem>, <directory path>) :param create_destination: If True, the destination will be created if it doesn't exist :param ignore_errors: If True, exceptions from file moves are ignored :param chunk_size: Size of chunks to move if a simple copy is used """ if not isinstance(fs1, tuple): raise ValueError( "first argument must be a tuple of (<filesystem>, <path>)") fs1, dir1 = fs1 parent_fs1 = fs1 parent_dir1 = dir1 fs1 = fs1.opendir(dir1) print fs1 if parent_dir1 in ('', '/'): raise RemoveRootError(dir1) if isinstance(fs2, tuple): fs2, dir2 = fs2 if create_destination: fs2.makedir(dir2, allow_recreate=True, recursive=True) fs2 = fs2.opendir(dir2) mount_fs = MountFS(auto_close=False) mount_fs.mount('src', fs1) mount_fs.mount('dst', fs2) mount_fs.copydir('src', 'dst', overwrite=True, ignore_errors=ignore_errors, chunk_size=chunk_size) parent_fs1.removedir(parent_dir1, force=True)
def movedir(fs1, fs2, create_destination=True, ignore_errors=False, chunk_size=64*1024): """Moves contents of a directory from one filesystem to another. :param fs1: A tuple of (<filesystem>, <directory path>) :param fs2: Destination filesystem, or a tuple of (<filesystem>, <directory path>) :param create_destination: If True, the destination will be created if it doesn't exist :param ignore_errors: If True, exceptions from file moves are ignored :param chunk_size: Size of chunks to move if a simple copy is used """ if not isinstance(fs1, tuple): raise ValueError("first argument must be a tuple of (<filesystem>, <path>)") fs1, dir1 = fs1 parent_fs1 = fs1 parent_dir1 = dir1 fs1 = fs1.opendir(dir1) print fs1 if parent_dir1 in ('', '/'): raise RemoveRootError(dir1) if isinstance(fs2, tuple): fs2, dir2 = fs2 if create_destination: fs2.makedir(dir2, allow_recreate=True, recursive=True) fs2 = fs2.opendir(dir2) mount_fs = MountFS(auto_close=False) mount_fs.mount('src', fs1) mount_fs.mount('dst', fs2) mount_fs.copydir('src', 'dst', overwrite=True, ignore_errors=ignore_errors, chunk_size=chunk_size) parent_fs1.removedir(parent_dir1, force=True)