mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 13:04:00 -07:00
archive: lzma is standard in Python 3.7+ (#10908)
* archive: lzma is standard in Python 3.7+ * add changelog frag
This commit is contained in:
parent
3734f471c1
commit
ce544f370c
2 changed files with 7 additions and 23 deletions
2
changelogs/fragments/10908-archive-lzma.yml
Normal file
2
changelogs/fragments/10908-archive-lzma.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- archive - remove conditional code for older Python versions (https://github.com/ansible-collections/community.general/pull/10908).
|
||||||
|
|
@ -179,6 +179,7 @@ import bz2
|
||||||
import glob
|
import glob
|
||||||
import gzip
|
import gzip
|
||||||
import io
|
import io
|
||||||
|
import lzma
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
|
@ -186,23 +187,12 @@ import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
|
from zipfile import BadZipFile
|
||||||
from zlib import crc32
|
from zlib import crc32
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||||
|
|
||||||
try: # python 3.2+
|
|
||||||
from zipfile import BadZipFile # type: ignore[attr-defined]
|
|
||||||
except ImportError: # older python
|
|
||||||
from zipfile import BadZipfile as BadZipFile
|
|
||||||
|
|
||||||
LZMA_IMP_ERR = None
|
|
||||||
try:
|
|
||||||
import lzma
|
|
||||||
HAS_LZMA = True
|
|
||||||
except ImportError:
|
|
||||||
LZMA_IMP_ERR = format_exc()
|
|
||||||
HAS_LZMA = False
|
|
||||||
|
|
||||||
STATE_ABSENT = 'absent'
|
STATE_ABSENT = 'absent'
|
||||||
STATE_ARCHIVED = 'archive'
|
STATE_ARCHIVED = 'archive'
|
||||||
|
|
@ -564,11 +554,8 @@ class TarArchive(Archive):
|
||||||
self.file.add(path, archive_name, recursive=False, filter=filter)
|
self.file.add(path, archive_name, recursive=False, filter=filter)
|
||||||
|
|
||||||
def _get_checksums(self, path):
|
def _get_checksums(self, path):
|
||||||
if HAS_LZMA:
|
LZMAError = lzma.LZMAError
|
||||||
LZMAError = lzma.LZMAError
|
|
||||||
else:
|
|
||||||
# Just picking another exception that's also listed below
|
|
||||||
LZMAError = tarfile.ReadError
|
|
||||||
try:
|
try:
|
||||||
if self.format == 'xz':
|
if self.format == 'xz':
|
||||||
with lzma.open(_to_native_ascii(path), 'r') as f:
|
with lzma.open(_to_native_ascii(path), 'r') as f:
|
||||||
|
|
@ -619,11 +606,6 @@ def main():
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not HAS_LZMA and module.params['format'] == 'xz':
|
|
||||||
module.fail_json(
|
|
||||||
msg=missing_required_lib("lzma or backports.lzma", reason="when using xz format"), exception=LZMA_IMP_ERR
|
|
||||||
)
|
|
||||||
|
|
||||||
check_mode = module.check_mode
|
check_mode = module.check_mode
|
||||||
|
|
||||||
archive = get_archive(module)
|
archive = get_archive(module)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue