def extract(self, path: Path, clean: bool = True): """ Extract the archive content. Parameters ---------- path : Path A non-existing directory path where the archive content is extracted clean : bool (default: True) Whether the archive content has to be cleaned from Mac OS hidden files (.DS_STORE, __MACOSX). """ if path.exists() and not path.is_dir(): raise ArchiveError( f"{self} cannot be extracted in {path} because " f"it already exists or it is not a directory" ) try: shutil.unpack_archive(self.absolute(), path, self._format.name) except shutil.ReadError as e: raise ArchiveError(str(e)) if clean: bad_filenames = ['.DS_STORE', '__MACOSX'] for bad_filename in bad_filenames: for bad_path in path.rglob(bad_filename): bad_path.unlink(missing_ok=True)
logging.basicConfig() logger = logging.getLogger("upload") logger.setLevel(logging.INFO) # Run me with: CONFIG_FILE=/path/to/config.env python import_local_images.py --path /my/folder if __name__ == '__main__': parser = ArgumentParser( prog="Import images sequentially to PIMS root from a local folder.") parser.add_argument( '--path', help="A directory with images to import, or an image path.") params, _ = parser.parse_known_args(sys.argv[1:]) path = Path(params.path) if not path.exists(): exit(-1) if path.is_file(): image_paths = [path] else: image_paths = [p for p in path.recursive_iterdir() if p.is_file()] for image_path in image_paths: # We have to copy to file to pending path first to pass importer validation. tmp_path = Path(PENDING_PATH) / image_path.name shutil.copy(image_path, tmp_path) try: run_import(tmp_path, image_path.name, prefer_copy=False) except Exception: # noqa tmp_path.unlink(missing_ok=True)
def test_basic_file(app, settings): path = Path(settings.root, "upload0/myfile.svs") assert path.exists() assert path.size == 0 assert (datetime.today() - path.creation_datetime).days == 0