Skip to content

Commit 5d07f11

Browse files
committed
try to fix invalid char
1 parent 6d18b14 commit 5d07f11

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

main.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def cleanup(*args):
4848
table_structure = {}
4949

5050
DUMP_CMD = 'mysqldump -h {host} -P {port} -u {user} --password={password} {db} {table} ' \
51-
'--default-character-set=utf8 -X' \
52-
.format(**config['mysql'])
53-
51+
'--default-character-set=utf8 -X'.format(**config['mysql'])
52+
REMOVE_INVALID_CHAR_CMD = 'tr -cd "[:print:]"'
5453

5554
BINLOG_CFG = {key: config['mysql'][key] for key in ['host', 'port', 'user', 'password', 'db']}
5655
BULK_SIZE = config.get('elastic').get('bulk_size')
@@ -301,13 +300,19 @@ def save_binlog_record():
301300

302301

303302
def xml_dump_loader():
304-
p = subprocess.Popen(
303+
mysqldump = subprocess.Popen(
305304
shlex.split(DUMP_CMD),
306305
stdout=subprocess.PIPE,
307306
stderr=subprocess.DEVNULL,
308307
close_fds=True)
309-
return p.stdout # can be used as file object. (stream io)
310308

309+
removed_invalid_char = subprocess.Popen(
310+
shlex.split(REMOVE_INVALID_CHAR_CMD),
311+
stdin=mysqldump.stdout,
312+
stdout=subprocess.PIPE,
313+
stderr=subprocess.DEVNULL,
314+
close_fds=True)
315+
return removed_invalid_char.stdout # can be used as file object. (stream io)
311316

312317
def xml_file_loader(filename):
313318
f = open(filename, 'rb') # bytes required

0 commit comments

Comments
 (0)