parent
a5e7492c4f
commit
e8b33636ae
1 changed files with 15 additions and 6 deletions
|
@ -81,17 +81,20 @@ class ZipFile(object):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.module = module
|
self.module = module
|
||||||
|
self.cmd_path = self.module.get_bin_path('unzip')
|
||||||
|
|
||||||
def is_unarchived(self):
|
def is_unarchived(self):
|
||||||
return dict(unarchived=False)
|
return dict(unarchived=False)
|
||||||
|
|
||||||
def unarchive(self):
|
def unarchive(self):
|
||||||
cmd = 'unzip -o "%s" -d "%s"' % (self.src, self.dest)
|
cmd = '%s -o "%s" -d "%s"' % (self.cmd_path, self.src, self.dest)
|
||||||
rc, out, err = self.module.run_command(cmd)
|
rc, out, err = self.module.run_command(cmd)
|
||||||
return dict(cmd=cmd, rc=rc, out=out, err=err)
|
return dict(cmd=cmd, rc=rc, out=out, err=err)
|
||||||
|
|
||||||
def can_handle_archive(self):
|
def can_handle_archive(self):
|
||||||
cmd = 'unzip -l "%s"' % self.src
|
if not self.cmd_path:
|
||||||
|
return False
|
||||||
|
cmd = '%s -l "%s"' % (self.cmd_path, self.src)
|
||||||
rc, out, err = self.module.run_command(cmd)
|
rc, out, err = self.module.run_command(cmd)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
return True
|
return True
|
||||||
|
@ -105,23 +108,26 @@ class TgzFile(object):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.module = module
|
self.module = module
|
||||||
|
self.cmd_path = self.module.get_bin_path('tar')
|
||||||
self.zipflag = 'z'
|
self.zipflag = 'z'
|
||||||
|
|
||||||
def is_unarchived(self):
|
def is_unarchived(self):
|
||||||
dirof = os.path.dirname(self.dest)
|
dirof = os.path.dirname(self.dest)
|
||||||
destbase = os.path.basename(self.dest)
|
destbase = os.path.basename(self.dest)
|
||||||
cmd = 'tar -v -C "%s" --diff -%sf "%s"' % (self.dest, self.zipflag, self.src)
|
cmd = '%s -v -C "%s" --diff -%sf "%s"' % (self.cmd_path, self.dest, self.zipflag, self.src)
|
||||||
rc, out, err = self.module.run_command(cmd)
|
rc, out, err = self.module.run_command(cmd)
|
||||||
unarchived = (rc == 0)
|
unarchived = (rc == 0)
|
||||||
return dict(unarchived=unarchived, rc=rc, out=out, err=err, cmd=cmd)
|
return dict(unarchived=unarchived, rc=rc, out=out, err=err, cmd=cmd)
|
||||||
|
|
||||||
def unarchive(self):
|
def unarchive(self):
|
||||||
cmd = 'tar -C "%s" -x%sf "%s"' % (self.dest, self.zipflag, self.src)
|
cmd = '%s -C "%s" -x%sf "%s"' % (self.cmd_path, self.dest, self.zipflag, self.src)
|
||||||
rc, out, err = self.module.run_command(cmd)
|
rc, out, err = self.module.run_command(cmd)
|
||||||
return dict(cmd=cmd, rc=rc, out=out, err=err)
|
return dict(cmd=cmd, rc=rc, out=out, err=err)
|
||||||
|
|
||||||
def can_handle_archive(self):
|
def can_handle_archive(self):
|
||||||
cmd = 'tar -t%sf "%s"' % (self.zipflag, self.src)
|
if not self.cmd_path:
|
||||||
|
return False
|
||||||
|
cmd = '%s -t%sf "%s"' % (self.cmd_path, self.zipflag, self.src)
|
||||||
rc, out, err = self.module.run_command(cmd)
|
rc, out, err = self.module.run_command(cmd)
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
if len(out.splitlines(True)) > 0:
|
if len(out.splitlines(True)) > 0:
|
||||||
|
@ -135,6 +141,7 @@ class TarFile(TgzFile):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.module = module
|
self.module = module
|
||||||
|
self.cmd_path = self.module.get_bin_path('tar')
|
||||||
self.zipflag = ''
|
self.zipflag = ''
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,6 +151,7 @@ class TarBzip(TgzFile):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.module = module
|
self.module = module
|
||||||
|
self.cmd_path = self.module.get_bin_path('tar')
|
||||||
self.zipflag = 'j'
|
self.zipflag = 'j'
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,6 +161,7 @@ class TarXz(TgzFile):
|
||||||
self.src = src
|
self.src = src
|
||||||
self.dest = dest
|
self.dest = dest
|
||||||
self.module = module
|
self.module = module
|
||||||
|
self.cmd_path = self.module.get_bin_path('tar')
|
||||||
self.zipflag = 'J'
|
self.zipflag = 'J'
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +172,7 @@ def pick_handler(src, dest, module):
|
||||||
obj = handler(src, dest, module)
|
obj = handler(src, dest, module)
|
||||||
if obj.can_handle_archive():
|
if obj.can_handle_archive():
|
||||||
return obj
|
return obj
|
||||||
raise RuntimeError('Failed to find handler to unarchive "%s"' % src)
|
module.fail_json(msg='Failed to find handler to unarchive. Make sure the required command to extract the file is installed.')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue