Skip to content

Commit

Permalink
Refactored write_text to write_text_tup and created write_text function
Browse files Browse the repository at this point in the history
  • Loading branch information
sfneal committed Nov 1, 2018
1 parent 8af56a0 commit dbea4e9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions mysql/toolkit/commands/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,36 @@ def dump_commands(commands, directory=None, sub_dir=None):
timer = Timer()
if MULTIPROCESS:
pool = Pool(cpu_count())
pool.map(write_text, command_filepath)
pool.map(write_text_tup, command_filepath)
pool.close()
print('\tDumped ', len(command_filepath), 'commands\n\t\tTime : {0}'.format(timer.end),
'\n\t\tMethod : (multiprocessing)\n\t\tDirectory : {0}'.format(dump_dir))
else:
for tup in command_filepath:
write_text(tup)
write_text_tup(tup)
print('\tDumped ', len(command_filepath), 'commands\n\t\tTime : {0}'.format(timer.end),
'\n\t\tMethod : (sequential)\n\t\tDirectory : {0}'.format(dump_dir))

# Return base directory of dumped commands
return return_dir


def write_text(tup):
def write_text(_command, txt_file):
"""Dump SQL command to a text file."""
command = _command.strip()
with open(txt_file, 'w') as txt:
txt.writelines(command)


def write_text_tup(tup):
"""
Dump SQL command to a text file.
:param tup: SQL command, text file path tuple
"""
# Unpack tuple, clean command and dump to text file
_command, txt_file = tup
command = _command.strip()
with open(txt_file, 'w') as txt:
txt.writelines(command)
write_text(_command, txt_file)


def get_commands_from_dir(directory, zip_backup=True, remove_dir=True):
Expand Down

0 comments on commit dbea4e9

Please sign in to comment.