mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Simplify code which prepares the decompression command
This commit is contained in:
parent
dd4838e4aa
commit
9b83311471
1 changed files with 6 additions and 12 deletions
|
@ -173,10 +173,8 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
||||||
if not all_databases:
|
if not all_databases:
|
||||||
cmd += " -D %s" % pipes.quote(db_name)
|
cmd += " -D %s" % pipes.quote(db_name)
|
||||||
if os.path.splitext(target)[-1] == '.gz':
|
if os.path.splitext(target)[-1] == '.gz':
|
||||||
zcat_path = module.get_bin_path('zcat')
|
comp_prog_path = module.get_bin_path('gzip', required=True)
|
||||||
if not zcat_path:
|
p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
module.fail_json(msg="zcat command not found")
|
|
||||||
p1 = subprocess.Popen([zcat_path, target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
(stdout2, stderr2) = p2.communicate()
|
(stdout2, stderr2) = p2.communicate()
|
||||||
p1.stdout.close()
|
p1.stdout.close()
|
||||||
|
@ -187,10 +185,8 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
||||||
else:
|
else:
|
||||||
return p2.returncode, stdout2, stderr2
|
return p2.returncode, stdout2, stderr2
|
||||||
elif os.path.splitext(target)[-1] == '.bz2':
|
elif os.path.splitext(target)[-1] == '.bz2':
|
||||||
bzcat_path = module.get_bin_path('bzcat')
|
comp_prog_path = module.get_bin_path('bzip2', required=True)
|
||||||
if not bzcat_path:
|
p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
module.fail_json(msg="bzcat command not found")
|
|
||||||
p1 = subprocess.Popen([bzcat_path, target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
(stdout2, stderr2) = p2.communicate()
|
(stdout2, stderr2) = p2.communicate()
|
||||||
p1.stdout.close()
|
p1.stdout.close()
|
||||||
|
@ -201,10 +197,8 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
||||||
else:
|
else:
|
||||||
return p2.returncode, stdout2, stderr2
|
return p2.returncode, stdout2, stderr2
|
||||||
elif os.path.splitext(target)[-1] == '.xz':
|
elif os.path.splitext(target)[-1] == '.xz':
|
||||||
xzcat_path = module.get_bin_path('xzcat')
|
comp_prog_path = module.get_bin_path('xz', required=True)
|
||||||
if not xzcat_path:
|
p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
module.fail_json(msg="xzcat command not found")
|
|
||||||
p1 = subprocess.Popen([xzcat_path, target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
||||||
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
(stdout2, stderr2) = p2.communicate()
|
(stdout2, stderr2) = p2.communicate()
|
||||||
p1.stdout.close()
|
p1.stdout.close()
|
||||||
|
|
Loading…
Reference in a new issue