<s> '''<STR_LIT>''' <EOL> import subprocess <EOL> import re <EOL> import sys <EOL> data_type_map = dict ( <EOL> varchar = '<STR_LIT:string>' , <EOL> int = '<STR_LIT>' , <EOL> integer = '<STR_LIT>' , <EOL> tinyint = '<STR_LIT>' , <EOL> smallint = '<STR_LIT>' , <EOL> mediumint = '<STR_LIT>' , <EOL> bigint = '<STR_LIT>' , <EOL> float = '<STR_LIT>' , <EOL> double = '<STR_LIT>' , <EOL> char = '<STR_LIT:string>' , <EOL> decimal = '<STR_LIT>' , <EOL> date = '<STR_LIT:date>' , <EOL> time = '<STR_LIT:time>' , <EOL> timestamp = '<STR_LIT>' , <EOL> datetime = '<STR_LIT>' , <EOL> binary = '<STR_LIT>' , <EOL> blob = '<STR_LIT>' , <EOL> tinyblob = '<STR_LIT>' , <EOL> mediumblob = '<STR_LIT>' , <EOL> longblob = '<STR_LIT>' , <EOL> text = '<STR_LIT:text>' , <EOL> tinytext = '<STR_LIT:text>' , <EOL> mediumtext = '<STR_LIT:text>' , <EOL> longtext = '<STR_LIT:text>' , <EOL> ) <EOL> def mysql ( database_name , username , password ) : <EOL> p = subprocess . Popen ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' % username , <EOL> '<STR_LIT>' % password , <EOL> '<STR_LIT>' , <EOL> database_name ] , <EOL> stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> sql_showtables , stderr = p . communicate ( ) <EOL> tables = [ re . sub ( <EOL> '<STR_LIT>' , '<STR_LIT>' , x ) for x in sql_showtables . split ( ) [ <NUM_LIT:1> : ] ] <EOL> connection_string = "<STR_LIT>" % ( <EOL> username , password , database_name ) <EOL> legacy_db_table_web2py_code = [ ] <EOL> for table_name in tables : <EOL> p = subprocess . Popen ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' % username , <EOL> '<STR_LIT>' % password , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , database_name , <EOL> table_name ] , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> sql_create_stmnt , stderr = p . communicate ( ) <EOL> if '<STR_LIT>' in sql_create_stmnt : <EOL> sql_lines = sql_create_stmnt . split ( '<STR_LIT:\n>' ) <EOL> sql_lines = filter ( <EOL> lambda x : not ( x in ( '<STR_LIT>' , '<STR_LIT:\r>' ) or x [ : <NUM_LIT:2> ] in ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> sql_lines ) <EOL> web2py_table_code = '<STR_LIT>' <EOL> table_name = re . search ( <EOL> '<STR_LIT>' , sql_lines [ <NUM_LIT:0> ] ) . group ( <NUM_LIT:1> ) <EOL> fields = [ ] <EOL> for line in sql_lines [ <NUM_LIT:1> : - <NUM_LIT:1> ] : <EOL> if re . search ( '<STR_LIT>' , line ) or re . search ( '<STR_LIT>' , line ) or re . search ( '<STR_LIT>' , line ) or line . startswith ( '<STR_LIT:)>' ) : <EOL> continue <EOL> hit = re . search ( '<STR_LIT>' , line ) <EOL> if hit is not None : <EOL> name , d_type = hit . group ( <NUM_LIT:1> ) , hit . group ( <NUM_LIT:2> ) <EOL> d_type = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , d_type ) <EOL> name = re . sub ( '<STR_LIT>' , '<STR_LIT>' , name ) <EOL> web2py_table_code += "<STR_LIT>" % ( <EOL> name , data_type_map [ d_type ] ) <EOL> web2py_table_code = "<STR_LIT>" % ( table_name , web2py_table_code ) <EOL> legacy_db_table_web2py_code . append ( web2py_table_code ) <EOL> legacy_db_web2py_code = connection_string + "<STR_LIT>" <EOL> legacy_db_web2py_code += "<STR_LIT>" . join ( <EOL> legacy_db_table_web2py_code ) <EOL> return legacy_db_web2py_code <EOL> regex = re . compile ( '<STR_LIT>' ) <EOL> if len ( sys . argv ) < <NUM_LIT:2> or not regex . match ( sys . argv [ <NUM_LIT:1> ] ) : <EOL> print '<STR_LIT>' <EOL> else : <EOL> m = regex . match ( sys . argv [ <NUM_LIT:1> ] ) <EOL> print mysql ( m . group ( <NUM_LIT:3> ) , m . group ( <NUM_LIT:1> ) , m . group ( <NUM_LIT:2> ) ) </s>
