def refresh_item(self): updated_file = fs_utils.parse_ls_output(fs_utils.ls(self.full_path))[0] self.size = updated_file.size self.permissions = updated_file.permissions self.modification_time = updated_file.modification_time self.owner = updated_file.owner self.group = updated_file.group
def copy(self, destination, force: bool = False, recursive: bool = False, dereference: bool = False): fs_utils.copy(str(self), destination, force, recursive, dereference) if fs_utils.check_if_directory_exists(destination): path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}" else: path = destination output = fs_utils.ls(f"{path}") return fs_utils.parse_ls_output(output)[0]
def _is_dev_path_blacklisted(path: str): """check if given path is blacklisted""" dev_by_id_dir = "/dev/disk/by-id" by_id_paths = parse_ls_output(ls(dev_by_id_dir), dev_by_id_dir) blacklist = ["/dev/disk/by-id/lvm", "/dev/disk/by-id/md-name"] for x in blacklist: for entry in by_id_paths: if not entry.full_path.startswith(x): continue if path == entry: return True return False
def chmod(self, permissions: fs_utils.Permissions, users: fs_utils.PermissionsUsers, sign: fs_utils.PermissionSign = fs_utils.PermissionSign.set, recursive: bool = False): fs_utils.chmod(self.full_path, permissions, users, sign=sign, recursive=recursive) output = fs_utils.ls(f"{self.full_path}") self.refresh_item()
def check_files(core, size_before, permissions_before, md5_before): TestRun.LOGGER.info("Checking file md5.") core.mount(mount_point) file_after = fs_utils.parse_ls_output(fs_utils.ls(test_file_path))[0] md5_after = file_after.md5sum() if md5_before != md5_after: TestRun.LOGGER.error(f"Md5 before ({md5_before}) and after ({md5_after}) are different.") if permissions_before.user == file_after.permissions.user: TestRun.LOGGER.error(f"User permissions before ({permissions_before.user}) " f"and after ({file_after.permissions.user}) are different.") if permissions_before.group != file_after.permissions.group: TestRun.LOGGER.error(f"Group permissions before ({permissions_before.group}) " f"and after ({file_after.permissions.group}) are different.") if permissions_before.other != file_after.permissions.other: TestRun.LOGGER.error(f"Other permissions before ({permissions_before.other}) " f"and after ({file_after.permissions.other}) are different.") if size_before != file_after.size: TestRun.LOGGER.error(f"Size before ({size_before}) and after ({file_after.size}) " f"are different.") core.unmount()
def ls(self): output = fs_utils.ls(f"{self.full_path}") return fs_utils.parse_ls_output(output, self.full_path)
def get_inode(file): file = ls(file, '-i') return file.split(' ')[0]
def create_file(path): fs_utils.create_file(path) output = fs_utils.ls(f"{path}") return fs_utils.parse_ls_output(output)[0]
def _is_by_id_path(path: str): """check if given path already is proper by-id path""" dev_by_id_dir = "/dev/disk/by-id" by_id_paths = parse_ls_output(ls(dev_by_id_dir), dev_by_id_dir) return path in [os.path.join(dev_by_id_dir, id_path.full_path) for id_path in by_id_paths]
def get_all_device_links(self, directory: str): from test_tools import fs_utils output = fs_utils.ls(f"$(find -L {directory} -samefile {self.system_path})") return fs_utils.parse_ls_output(output, self.system_path)