def smart_extract(self, archive_path: str, extract_path: str) -> None: "make extract from archive, when needed" if SUDO.folder_check(extract_path): logger.debug(f"smart.extract.present: {extract_path}") archive_head = discover_header(archive_path) extract_head = discover_header(extract_path) head_comp = compare_header(archive_head, extract_head) logger.debug(f"smart.extract.{head_comp}: {extract_path}") if head_comp == HeadComp.same: pass elif head_comp == HeadComp.different: logger.debug( f"smart.extract.{head_comp}: archive={archive_head}") logger.debug( f"smart.extract.{head_comp}: extract={extract_head}") self.extract(archive_path, extract_path) elif head_comp == HeadComp.undetermined: logger.debug( f"smart.extract.{head_comp}: archive={archive_head}") logger.debug( f"smart.extract.{head_comp}: extract={extract_head}") self.extract(archive_path, extract_path) else: assert False, f"wrong head_comp: {head_comp}" else: logger.debug(f"smart.extract.missing: {extract_path}") self.extract(archive_path, extract_path)
def image_type_form(extract_path: str) -> ImageType: for entry in image_type_list: has_root = False if entry.root_path is None: has_root = True else: root_path = extract_path + entry.root_path has_root = SUDO.folder_check(root_path) has_meta = False if entry.meta_path is None: has_meta = True else: meta_path = extract_path + entry.meta_path has_meta = SUDO.file_check(meta_path) if has_root and has_meta: return entry raise Exception(f"missing type for {extract_path}")
def extract(self, archive_path: str, extract_path: str) -> None: logger.debug(f"pack.extract.tar: {extract_path}") SUDO.file_assert(archive_path) extract_temp = make_temp_path("tar-extract-temp") SUDO.folder_ensure(extract_temp) tar = Tar() tar.with_archive(archive_path) tar.with_extract(extract_temp) tar.with_packer(archive_path) tar.with_make_unpack() # keep last tar.execute_unit_sert() if SUDO.folder_check(extract_path): # user rsync to preserve active machines SUDO.files_sync_full(extract_temp, extract_path) SUDO.files_delete(extract_temp) else: # user move for efficiency SUDO.files_move(extract_temp, extract_path) synchronize_header(archive_path, extract_path)
def has_extract(self) -> bool: return SUDO.folder_check(self.extract_path())