def list_environment_files(self): if not self.is_initialized: raise FileStructureError( __("error", "controller.file.driver.local.list_file_collections")) environment_files_list = os.listdir(self.environment_directory_path) return environment_files_list
def create_collection(self, paths): if not self.is_initialized: raise FileStructureError( __("error", "controller.file.driver.local.create_collection.structure")) self.ensure_collections_dir() temp_collection_path = get_datmo_temp_path(self.root) filehash = self.calculate_hash_paths(paths, temp_collection_path) # Move contents to folder with filehash as name and remove temp_collection_path collection_path = os.path.join(self.datmo_directory, "collections", filehash) if os.path.isdir(collection_path): return filehash # raise FileStructureError("exception.file.create_collection", { # "exception": "File collection with id already exists." # }) os.makedirs(collection_path) self.copytree(temp_collection_path, collection_path) # Change permissions to read only for collection_path. File collection is immutable mode = stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH for root, dirs, files in os.walk(collection_path, topdown=False): for dir in [os.path.join(root, d) for d in dirs]: os.chmod(dir, mode) for file in [os.path.join(root, f) for f in files]: os.chmod(file, mode) return filehash
def create_environment_dir(self): if not os.path.isdir(self._datmo_directory_path): raise FileStructureError( __("error", "controller.file.driver.local.create_collections_dir")) if not os.path.isdir(self.environment_directory_path): os.makedirs(self.environment_directory_path) return True
def list_file_collections(self): if not self.is_initialized: raise FileStructureError( __("error", "controller.file.driver.local.list_file_collections")) collections_path = os.path.join(self.datmo_directory, "collections") collections_list = os.listdir(collections_path) return collections_list
def create_files_dir(self): if not self.exists_hidden_datmo_dir(): raise FileStructureError( __("error", "controller.file.driver.local.create_collections_dir")) relative_files_path = os.path.join(self.datmo_directory_name, "files") if not self.exists(relative_files_path, directory=True): self.create(relative_files_path, directory=True) return True