def read(self): confReader = GlobConfReader(self.conf_file) confReader.read() db_conn_dict = {} for key, db_conn_str in confReader.get_db_conf_dict().items(): host, dbname, port, user, passwd = map(lambda x: x.strip(), db_conn_str.split(":")) db_conn_dict[key] = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname, charset="utf8") data_results = [] for schema_name in confReader.get_schema_list(): key_name, table_name = schema_name.strip().split("_", 1) schema_file = "%s/%s.schema" % (self.schema_dir, schema_name) schemaReader = SchemaReader(schema_file) schemaReader.read() data_results.append((table_name, {})) sql_cmd = "select %s from %s" % (schemaReader.get_field_list_str(), table_name) conn = db_conn_dict[key_name] cursor = conn.cursor() cursor.execute(sql_cmd) for fields in cursor.fetchall(): temp_list = map(lambda x: str(x), fields) primary_key_value = schemaReader.get_primary_key_value(temp_list) data_results[-1][1][primary_key_value] = temp_list file = open(self.output_file, "w") pickle.dump(data_results, file) file.close()
def write(self): confReader = GlobConfReader(self.conf_file) confReader.read() db_conn_dict = {} for key, db_conn_str in confReader.get_db_conf_dict().items(): host, dbname, port, user, passwd = map(lambda x: x.strip(), db_conn_str.split(":")) db_conn_dict[key] = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname, charset="utf8") schema_list = confReader.get_schema_list() table_data_list = pickle.load(open(self.data_file)) for idx, table_info in enumerate(table_data_list): schema_name = schema_list[idx] prod_type_str, table_name = schema_name.split("_", 1) schema_file = "%s/%s.schema" % (self.schema_dir, schema_name) conn = db_conn_dict[prod_type_str] schemaReader = SchemaReader(schema_file, conn) schemaReader.read() default_value_set = schemaReader.get_default_value_set() if default_value_set != None: def_key_str, def_value_str = map(lambda x: x.strip(), default_value_set.split(":", 1)) else: def_key_str, def_value_str = None, None cursor = conn.cursor() table_name, data_dict = table_info sql_del_cmd = "delete from %s" % (table_name) cursor.execute(sql_del_cmd) for key, row_data_list in data_dict.items(): row_data_list = schemaReader.get_insert_row(row_data_list) if def_value_str == None: sql_cmd = "insert into %s (%s) values (%s)" % (table_name, schemaReader.get_field_list_str(), ",".join(row_data_list)) else: sql_cmd = "insert into %s (%s) values (%s)" % (table_name, schemaReader.get_field_list_str() + "," + def_key_str, ",".join(row_data_list) + "," + def_value_str) cursor.execute(sql_cmd) conn.commit() cursor.close()
def write(self): confReader = GlobConfReader(self.conf_file) confReader.read() db_conn_dict = {} for key, db_conn_str in confReader.get_db_conf_dict().items(): host, dbname, port, user, passwd = map(lambda x: x.strip(), db_conn_str.split(":")) db_conn_dict[key] = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname, charset="utf8") schema_list = confReader.get_schema_list() table_data_list = pickle.load(open(self.data_file)) for idx, table_info in enumerate(table_data_list): schema_name = schema_list[idx] prod_type_str, table_name = schema_name.split("_", 1) schema_file = "%s/%s.schema" % (self.schema_dir, schema_name) conn = db_conn_dict[prod_type_str] schemaReader = SchemaReader(schema_file, conn) schemaReader.read() default_value_set = schemaReader.get_default_value_set() if default_value_set != None: def_key_str, def_value_str = map( lambda x: x.strip(), default_value_set.split(":", 1)) else: def_key_str, def_value_str = None, None cursor = conn.cursor() table_name, data_dict = table_info sql_del_cmd = "delete from %s" % (table_name) cursor.execute(sql_del_cmd) for key, row_data_list in data_dict.items(): row_data_list = schemaReader.get_insert_row(row_data_list) if def_value_str == None: sql_cmd = "insert into %s (%s) values (%s)" % ( table_name, schemaReader.get_field_list_str(), ",".join(row_data_list)) else: sql_cmd = "insert into %s (%s) values (%s)" % ( table_name, schemaReader.get_field_list_str() + "," + def_key_str, ",".join(row_data_list) + "," + def_value_str) cursor.execute(sql_cmd) conn.commit() cursor.close()
def read(self): confReader = GlobConfReader(self.conf_file) confReader.read() db_conn_dict = {} for key, db_conn_str in confReader.get_db_conf_dict().items(): host, dbname, port, user, passwd = map(lambda x: x.strip(), db_conn_str.split(":")) db_conn_dict[key] = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname, charset="utf8") data_results = [] for schema_name in confReader.get_schema_list(): key_name, table_name = schema_name.strip().split("_", 1) schema_file = "%s/%s.schema" % (self.schema_dir, schema_name) schemaReader = SchemaReader(schema_file) schemaReader.read() data_results.append((table_name, {})) sql_cmd = "select %s from %s" % (schemaReader.get_field_list_str(), table_name) conn = db_conn_dict[key_name] cursor = conn.cursor() cursor.execute(sql_cmd) for fields in cursor.fetchall(): temp_list = map(lambda x: str(x), fields) primary_key_value = schemaReader.get_primary_key_value( temp_list) data_results[-1][1][primary_key_value] = temp_list file = open(self.output_file, "w") pickle.dump(data_results, file) file.close()
def check_list(self, data_list1, data_list2): ret_list = [ "<html>", "<head>", "<meta charset='utf8'>", "</head>", "<body>", ] title_list = [] body_list = [] confReader = GlobConfReader(self.conf_file) confReader.read() schema_list = confReader.get_schema_list() data_list1_len = len(data_list1) data_list2_len = len(data_list2) if data_list1_len != data_list2_len: pass for idx in range(data_list1_len): schema_name = schema_list[idx] schema_file = "%s/%s.schema" % (self.schema_dir, schema_name) schemaReader = SchemaReader(schema_file) schemaReader.read() field_name_list = schemaReader.get_field_name_list() field_name_html_str = "<tr><th>" + "</th><th>".join( field_name_list) + "</th></tr>" table1_name, table1_data_dict = data_list1[idx] table2_name, table2_data_dict = data_list2[idx] if table1_name != table2_name: pass sort_key_list = [] sort_key_list.extend(table1_data_dict.keys()) for key in table2_data_dict.keys(): if key not in sort_key_list: sort_key_list.append(key) # 按数字排序 sort_key_list.sort(cmp=lambda x, y: cmp(int(x), int(y))) list1_html, list2_html, is_same = self.get_html_result( schemaReader, sort_key_list, table1_data_dict, table2_data_dict) if is_same == True: title_list.append("<td><a href=''>" + table1_name + "</a></td>") else: title_list.append("<td><a class=red href=''>" + table1_name + "</a></td>") body_list.append("<table border='1' class='table_results' name='" + table1_name + "'>") body_list.append("<thead><tr><th colspan=" + str(schemaReader.get_fields_count()) + ">" + table1_name + "(" + schemaReader.get_table_name() + " 1)" + "</th></tr></thead>") body_list.append(field_name_html_str) body_list.extend(list1_html) # body_list.append("<tr><th colspan=" + str(schemaReader.get_fields_count()) + ">状态二</th></tr>") body_list.append("<tr><th colspan=" + str(schemaReader.get_fields_count()) + ">" + table1_name + "(" + schemaReader.get_table_name() + " 2)" + "</th></tr>") body_list.extend(list2_html) body_list.append("</table>") ret_list.append("<table border='1' id='index_table'><tr>" + "\n".join(title_list) + "</tr></table>") ret_list.append("<br>") ret_list.append("\n".join(body_list)) ret_list.append("</body>") ret_list.append("</html>") print "\n".join(ret_list)
def check_list(self, data_list1, data_list2): ret_list = [ "<html>", "<head>", "<meta charset='utf8'>", "</head>", "<body>", ] title_list = [] body_list = [] confReader = GlobConfReader(self.conf_file) confReader.read() schema_list = confReader.get_schema_list() data_list1_len = len(data_list1) data_list2_len = len(data_list2) if data_list1_len != data_list2_len: pass for idx in range(data_list1_len): schema_name = schema_list[idx] schema_file = "%s/%s.schema" % (self.schema_dir, schema_name) schemaReader = SchemaReader(schema_file) schemaReader.read() field_name_list = schemaReader.get_field_name_list() field_name_html_str = "<tr><th>" + "</th><th>".join(field_name_list) + "</th></tr>" table1_name, table1_data_dict = data_list1[idx] table2_name, table2_data_dict = data_list2[idx] if table1_name != table2_name: pass sort_key_list = [] sort_key_list.extend(table1_data_dict.keys()) for key in table2_data_dict.keys(): if key not in sort_key_list: sort_key_list.append(key) # 按数字排序 sort_key_list.sort(cmp=lambda x,y:cmp(int(x), int(y))) list1_html, list2_html, is_same = self.get_html_result(schemaReader, sort_key_list, table1_data_dict, table2_data_dict) if is_same == True: title_list.append("<td><a href=''>" + table1_name + "</a></td>") else: title_list.append("<td><a class=red href=''>" + table1_name + "</a></td>") body_list.append("<table border='1' class='table_results' name='" + table1_name + "'>") body_list.append("<thead><tr><th colspan=" + str(schemaReader.get_fields_count()) + ">" + table1_name + "(" + schemaReader.get_table_name() + " 1)" + "</th></tr></thead>") body_list.append(field_name_html_str) body_list.extend(list1_html) # body_list.append("<tr><th colspan=" + str(schemaReader.get_fields_count()) + ">状态二</th></tr>") body_list.append("<tr><th colspan=" + str(schemaReader.get_fields_count()) + ">" + table1_name + "(" + schemaReader.get_table_name() + " 2)" + "</th></tr>") body_list.extend(list2_html) body_list.append("</table>") ret_list.append("<table border='1' id='index_table'><tr>" + "\n".join(title_list) + "</tr></table>") ret_list.append("<br>"); ret_list.append("\n".join(body_list)) ret_list.append("</body>") ret_list.append("</html>") print "\n".join(ret_list)