def gc_sql(user, pwd, db, table, has_data):
    '''
    生成 sql 文件
    '''
    if has_data:
        sys_order = "mysqldump -u%s -p%s %s %s > %s/%s.sql"%(user, pwd, db, table, temp_path, table)
    else:
        sys_order = "mysqldump -u%s -p%s -d %s %s > %s/%s.sql"%(user, pwd, db, table, temp_path, table)
    try:
        res = os.system(sys_order)
        if res == 0:
            print("生成%s表sql文件。"%table)
    except Exception as e:
        print(e)
def clear_temp():
    '''
    每次执行的时候调用这个,先清理下temp目录下面的旧文件
    '''
    if os.path.exists(temp_path):
        files = os.listdir(temp_path)
        for file in files:
            f = os.path.join(temp_path, file)
            if os.path.isfile(f):
                os.remove(f)
    print("临时文件目录清理完成")
if __name__ == "__main__":
    test1_config = {
        "user" : "root", 
        "password" : "root",
        "database" : "test1", 
    }
    test2_config = {
        "user" : "root", 
        "password" : "root",
        "database" : "test2", 
    }
    
    test1_dao = BaseDao(**test1_config)
    test1_struts = test1_dao.select_database_struts()
    
    test2_dao = BaseDao(**test2_config)
    test2_struts = test2_dao.select_database_struts()
main(test2_struts, test1_struts)
目前只支持了4种SQL脚本的生成。

