X-Git-Url: https://git.phdru.name/?p=sqlconvert.git;a=blobdiff_plain;f=scripts%2Fmysql2sql;h=e63c1fd8f5942f0735256d5aae12e51e3ebd318a;hp=e4f2e4bbf9fa0eb9c84c1759fcd41cc79b13cfb0;hb=HEAD;hpb=de3d7d28c48e20deb385c7b7a21b404cd42ce31d diff --git a/scripts/mysql2sql b/scripts/mysql2sql index e4f2e4b..e859f2a 100755 --- a/scripts/mysql2sql +++ b/scripts/mysql2sql @@ -6,7 +6,6 @@ from io import open import os import sys -from sqlparse.compat import text_type from sqlconvert.print_tokens import print_tokens from sqlconvert.process_mysql import is_directive_statement, process_statement from sqlconvert.process_tokens import is_newline_statement, StatementGrouper @@ -14,6 +13,11 @@ from sqlconvert.process_tokens import is_newline_statement, StatementGrouper from m_lib.defenc import default_encoding from m_lib.pbar.tty_pbar import ttyProgressBar +try: + text_type = unicode +except NameError: + text_type = str + def get_fsize(fp): try: @@ -31,8 +35,12 @@ def main(infile, encoding, outfile, output_encoding, use_pbar, quoting_style): if size is None: use_pbar = False - print("Converting: ", end='', file=sys.stderr) - sys.stderr.flush() + if use_pbar: + print("Converting", end='', file=sys.stderr) + if infile.name != '': + print(' ' + infile.name, end='', file=sys.stderr) + print(": ", end='', file=sys.stderr) + sys.stderr.flush() if use_pbar: pbar = ttyProgressBar(0, size-1) @@ -56,8 +64,8 @@ def main(infile, encoding, outfile, output_encoding, use_pbar, quoting_style): got_directive = is_directive_statement(statement) if got_directive: continue - for statement in process_statement(statement, quoting_style): - print_tokens(statement, outfile=outfile, + for _statement in process_statement(statement, quoting_style): + print_tokens(_statement, outfile=outfile, encoding=output_encoding) tokens = grouper.close() if tokens: @@ -66,7 +74,7 @@ def main(infile, encoding, outfile, output_encoding, use_pbar, quoting_style): if use_pbar: pbar.erase() - print("done.") + print("done.") if __name__ == '__main__': parser = argparse.ArgumentParser(description='Convert MySQL to SQL') @@ -133,6 +141,7 @@ if __name__ == '__main__': if outfile == '-': outfile = sys.stdout + args.no_pbar = True else: try: outfile = open(outfile, 'wt', encoding=output_encoding)