diff options
Diffstat (limited to 'libmat2/archive.py')
| -rw-r--r-- | libmat2/archive.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libmat2/archive.py b/libmat2/archive.py index f788ecc..80e0bf2 100644 --- a/libmat2/archive.py +++ b/libmat2/archive.py | |||
| @@ -67,6 +67,31 @@ class ArchiveBasedAbstractParser(abstract.AbstractParser): | |||
| 67 | 67 | ||
| 68 | return metadata | 68 | return metadata |
| 69 | 69 | ||
| 70 | def get_meta(self) -> Dict[str, Union[str, dict]]: | ||
| 71 | meta = dict() # type: Dict[str, Union[str, dict]] | ||
| 72 | |||
| 73 | with zipfile.ZipFile(self.filename) as zin: | ||
| 74 | temp_folder = tempfile.mkdtemp() | ||
| 75 | |||
| 76 | for item in zin.infolist(): | ||
| 77 | if item.filename[-1] == '/': # pragma: no cover | ||
| 78 | # `is_dir` is added in Python3.6 | ||
| 79 | continue # don't keep empty folders | ||
| 80 | |||
| 81 | zin.extract(member=item, path=temp_folder) | ||
| 82 | full_path = os.path.join(temp_folder, item.filename) | ||
| 83 | |||
| 84 | tmp_parser, _ = parser_factory.get_parser(full_path) # type: ignore | ||
| 85 | if not tmp_parser: | ||
| 86 | continue | ||
| 87 | |||
| 88 | local_meta = tmp_parser.get_meta() | ||
| 89 | if local_meta: | ||
| 90 | meta[item.filename] = local_meta | ||
| 91 | |||
| 92 | shutil.rmtree(temp_folder) | ||
| 93 | return meta | ||
| 94 | |||
| 70 | def remove_all(self) -> bool: | 95 | def remove_all(self) -> bool: |
| 71 | # pylint: disable=too-many-branches | 96 | # pylint: disable=too-many-branches |
| 72 | 97 | ||
