mirror of
https://github.com/ansible/awx.git
synced 2026-05-18 06:47:41 -02:30
Merge pull request #8057 from ryanpetrello/proj-archive-py2
update the project archive sync support for py2 compatability Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -2,15 +2,21 @@ from __future__ import absolute_import, division, print_function
|
|||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
import zipfile
|
import errno
|
||||||
import tarfile
|
|
||||||
import os
|
import os
|
||||||
|
import tarfile
|
||||||
|
import zipfile
|
||||||
|
|
||||||
from ansible.plugins.action import ActionBase
|
from ansible.plugins.action import ActionBase
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
try:
|
||||||
|
from zipfile import BadZipFile
|
||||||
|
except ImportError:
|
||||||
|
from zipfile import BadZipfile as BadZipFile # py2 compat
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(ActionBase):
|
class ActionModule(ActionBase):
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
@@ -26,14 +32,15 @@ class ActionModule(ActionBase):
|
|||||||
archive = zipfile.ZipFile(src)
|
archive = zipfile.ZipFile(src)
|
||||||
get_filenames = archive.namelist
|
get_filenames = archive.namelist
|
||||||
get_members = archive.infolist
|
get_members = archive.infolist
|
||||||
except zipfile.BadZipFile:
|
except BadZipFile:
|
||||||
archive = tarfile.open(src)
|
try:
|
||||||
|
archive = tarfile.open(src)
|
||||||
|
except tarfile.ReadError:
|
||||||
|
result["failed"] = True
|
||||||
|
result["msg"] = "{0} is not a valid archive".format(src)
|
||||||
|
return result
|
||||||
get_filenames = archive.getnames
|
get_filenames = archive.getnames
|
||||||
get_members = archive.getmembers
|
get_members = archive.getmembers
|
||||||
except tarfile.ReadError:
|
|
||||||
result["failed"] = True
|
|
||||||
result["msg"] = "{0} is not a valid archive".format(src)
|
|
||||||
return result
|
|
||||||
|
|
||||||
# Most well formed archives contain a single root directory, typically named
|
# Most well formed archives contain a single root directory, typically named
|
||||||
# project-name-1.0.0. The project contents should be inside that directory.
|
# project-name-1.0.0. The project contents should be inside that directory.
|
||||||
@@ -62,10 +69,19 @@ class ActionModule(ActionBase):
|
|||||||
try:
|
try:
|
||||||
is_dir = member.is_dir()
|
is_dir = member.is_dir()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
is_dir = member.isdir()
|
try:
|
||||||
|
is_dir = member.isdir()
|
||||||
|
except AttributeError:
|
||||||
|
is_dir = member.filename[-1] == '/' # py2 compat for ZipInfo
|
||||||
|
|
||||||
if is_dir:
|
if is_dir:
|
||||||
os.makedirs(dest, exist_ok=True)
|
try:
|
||||||
|
os.makedirs(dest)
|
||||||
|
except OSError as exc: # Python >= 2.5
|
||||||
|
if exc.errno == errno.EEXIST and os.path.isdir(dest):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
member_f = archive.open(member)
|
member_f = archive.open(member)
|
||||||
|
|||||||
Reference in New Issue
Block a user