summaryrefslogtreecommitdiff
path: root/database/mysql/mysql_db.py
diff options
context:
space:
mode:
authorfdupoux <fdupoux@users.sourceforge.net>2015-05-25 20:22:49 +0100
committerfdupoux <fdupoux@users.sourceforge.net>2015-05-25 20:22:49 +0100
commit380b122d5a1ec2928b2ec10eb67c1908038fb7ae (patch)
tree605017275e1d9bfa5bc694a56abb34ccee36fa89 /database/mysql/mysql_db.py
parentf634c10636428c78575aa4d54b19dfd53e812dae (diff)
downloadansible-modules-core-380b122d5a1ec2928b2ec10eb67c1908038fb7ae.tar.gz
Refactoring to avoid duplication of code which manages the decompression of database dumps in various formats
Diffstat (limited to 'database/mysql/mysql_db.py')
-rw-r--r--database/mysql/mysql_db.py26
1 files changed, 5 insertions, 21 deletions
diff --git a/database/mysql/mysql_db.py b/database/mysql/mysql_db.py
index b5af4840..fd6f82b4 100644
--- a/database/mysql/mysql_db.py
+++ b/database/mysql/mysql_db.py
@@ -166,32 +166,16 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
cmd += " --host=%s --port=%i" % (pipes.quote(host), port)
if not all_databases:
cmd += " -D %s" % pipes.quote(db_name)
+
+ comp_prog_path = None
if os.path.splitext(target)[-1] == '.gz':
comp_prog_path = module.get_bin_path('gzip', required=True)
- p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stdout2, stderr2) = p2.communicate()
- p1.stdout.close()
- p1.wait()
- if p1.returncode != 0:
- stderr1 = p1.stderr.read()
- return p1.returncode, '', stderr1
- else:
- return p2.returncode, stdout2, stderr2
elif os.path.splitext(target)[-1] == '.bz2':
comp_prog_path = module.get_bin_path('bzip2', required=True)
- p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stdout2, stderr2) = p2.communicate()
- p1.stdout.close()
- p1.wait()
- if p1.returncode != 0:
- stderr1 = p1.stderr.read()
- return p1.returncode, '', stderr1
- else:
- return p2.returncode, stdout2, stderr2
elif os.path.splitext(target)[-1] == '.xz':
comp_prog_path = module.get_bin_path('xz', required=True)
+
+ if comp_prog_path:
p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout2, stderr2) = p2.communicate()
@@ -205,7 +189,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
else:
cmd += " < %s" % pipes.quote(target)
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
- return rc, stdout, stderr
+ return rc, stdout, stderr
def db_create(cursor, db, encoding, collation):
query_params = dict(enc=encoding, collate=collation)