Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/galaxy/tool_util/verify/asserts/archive.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author | shellac |
---|---|
date | Mon, 22 Mar 2021 18:12:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4f3585e2f14b |
---|---|
1 import io | |
2 import re | |
3 import tarfile | |
4 import zipfile | |
5 | |
6 | |
7 def _extract_from_tar(tar_temp, path): | |
8 for fn in tar_temp.getnames(): | |
9 if re.match(path, fn): | |
10 # Will only match on first hit, probably fine for now | |
11 return tar_temp.extractfile(fn) | |
12 | |
13 | |
14 def _extract_from_zip(zip_temp, path): | |
15 for fn in zip_temp.namelist(): | |
16 if re.match(path, fn): | |
17 # Will only match on first hit, probably fine for now | |
18 return zip_temp.open(fn) | |
19 | |
20 | |
21 def assert_has_archive_member(output_bytes, path, verify_assertions_function, children): | |
22 """ Recursively checks the specified children assertions against the text of | |
23 the first element matching the specified path found within the archive. | |
24 Currently supported formats: .zip, .tar, .tar.gz.""" | |
25 | |
26 output_temp = io.BytesIO(output_bytes) | |
27 try: # tar / tar.gz | |
28 temp = tarfile.open(fileobj=output_temp, mode='r') | |
29 contents = _extract_from_tar(temp, path) | |
30 except tarfile.TarError: # zip | |
31 temp = zipfile.ZipFile(output_temp, mode='r') | |
32 contents = _extract_from_zip(temp, path) | |
33 finally: | |
34 verify_assertions_function(contents.read(), children) | |
35 contents.close() | |
36 temp.close() | |
37 output_temp.close() |