def delete_keys(result): key_name = result[1] value1 = set() value2 = {result[1]: []} for table in tables.keys(): regex = tables[table]["regex"] type_ = tables[table]['key_type'] format_ = tables[table].get("format", "") if re.match(regex, key_name): if type_ == "hash": value2[result[1]] = [] query_table = tables[table]["object"]() primary_keys = migration.get_primary_key_value(tables[table], value2) where_clause_parameter = [str(query_table.__table__.c[k[5:]] == migration.bindparam(k)) for k in primary_keys.keys()] where_clause_parameter = "".join(where_clause_parameter) stmt = query_table.__table__.select() \ .where(where_clause_parameter) conn = migration.engine.connect() res = conn.execute(stmt, **primary_keys) for i in res: k = i[1].split(" ") for j in k: value1.add(j) value2[key_name] = list(value1) keys_delete = {} keys_delete = {result[1]: value2[key_name], **keys_delete} migration.bulk_deletion(keys_delete, tables) print("{} key is deleted".format(key_name)) else: value2[result[1]] = [] key = result[1] key_value = value2[result[1]] query_table = tables[table]["object"]() values = {} for column in tables[table]['fields']: if column['source'] == "pattern": values[column['column_name']] = migration.get_value_from_source(column['source'], key, key_value, regex, column['value'], format_, type_) primary_keys = {} for column in values.keys(): primary_keys["bind_" + column] = values[column] where_clause_parameter = [str(query_table.__table__.c[k[5:]] == migration.bindparam(k)) for k in primary_keys.keys()] where_clause_parameter = "".join(where_clause_parameter) stmt = query_table.__table__.delete().where(where_clause_parameter) conn = migration.engine.connect() conn.execute(stmt, **primary_keys) migration.Session.commit() print("{} key is deleted".format(key_name)) return value2
def test_insert_cont(self): key_name = "questions:666665:answers" value2 = {} value1 = set() value3 = set() value2[key_name] = "9" value1.add("9") print("value1") print(value1) keys = {} keys = {key_name: value2[key_name], **keys} migration.bulk_insertion(keys, self.tables) migration.Session.commit() for table in self.tables.keys(): regex = self.tables[table]["regex"] if re.match(regex, key_name): query_table = self.tables[table]["object"]() primary_keys = migration.get_primary_key_value( self.tables[table], value2) where_clause_parameter = [ str(query_table.__table__.c[k[5:]] == migration.bindparam( k)) for k in primary_keys.keys() ] where_clause_parameter = " ".join(where_clause_parameter) stmt = query_table.__table__.select() \ .where(where_clause_parameter) conn = migration.engine.connect() res = conn.execute(stmt, **primary_keys) for i in res: print("res") print(i) k = i[1].split(" ") for j in k: value3.add(j) print("value3") print(value3) break self.assertEqual(value3, value1)
def sorted_sets(result): key_name = result[1] value2 = {result[1]: {}} value1 = set() for table in tables.keys(): regex = tables[table]["regex"] if re.match(regex, key_name): query_table = tables[table]["object"]() primary_keys = migration.get_primary_key_value(tables[table], value2) where_clause_parameter = [str(query_table.__table__.c[k[5:]] == migration.bindparam(k)) for k in primary_keys.keys()] where_clause_parameter = " ".join(where_clause_parameter) stmt = query_table.__table__.select() \ .where(where_clause_parameter) conn = migration.engine.connect() res = conn.execute(stmt, **primary_keys) for sorted_sets_name in res: k = sorted_sets_name[1].split(" ") value1 = set() for j in k: value1.add(j) if value1 == set(): break else: if len(result) == 4: value1.add(result[2]) else: new = result[2:] eff_length = len(new) wanted_parts = eff_length // 2 result1 = split_list(new, wanted_parts) for item in result1: item.insert(0, key_name) value1.add(item[1]) value2[result[1]] = list(value1) keys = {} keys = {key_name: value2[key_name], **keys} migration.update(keys, tables[table]) print("{} key is changed".format(key_name)) return value2 if len(result) == 4: value2[result[1]][result[3]] = result[2] keys = {} keys = {key_name: value2[result[1]], **keys} migration.bulk_insertion(keys, tables) print("{} key is changed".format(key_name)) return value2 else: new = result[2:] eff_length = len(new) wanted_parts = eff_length // 2 result1 = split_list(new, wanted_parts) for item in result1: value2[result[1]][str(item[1])] = item[0] item.insert(0, key_name) keys = {} keys = {key_name: value2[result[1]], **keys} migration.bulk_insertion(keys, tables) migration.Session.commit() print("{} key is changed".format(key_name)) return value2
def lists(result): key_name = result[1] command = result[0] value2 = {result[1]: []} for table in tables.keys(): regex = tables[table]["regex"] if re.match(regex, key_name): value2[result[1]] = [result[2]] query_table = tables[table]["object"]() primary_keys = migration.get_primary_key_value(tables[table], value2) where_clause_parameter = [str(query_table.__table__.c[k[5:]] == migration.bindparam(k)) for k in primary_keys.keys()] where_clause_parameter = " ".join(where_clause_parameter) stmt = query_table.__table__.select() \ .where(where_clause_parameter) conn = migration.engine.connect() res = conn.execute(stmt, **primary_keys) for i in res: k = i[1].split(" ") value1 = set() for j in k: value1.add(j) if value1 == set(): break else: if command == "lrem": value = set() number = (int(result[2])) while number <= 0: value.add(result[3]) number = number + 1 value2[result[1]] = list(value1-value) keys_delete = {} keys_delete = {result[1]: value2[result[1]], **keys_delete} migration.bulk_insertion(keys_delete, tables) print("{} key is changed".format(key_name)) return value2 if len(result) == 3: value1.add(result[2]) else: new = result[2:] for list_name in new: value1.add(list_name) value2[result[1]] = list(value1) keys = {} keys = {key_name: value2[key_name], **keys} migration.update(keys, tables[table]) print("{} key is changed".format(key_name)) return value2 if len(result) == 3: value2[result[1]] = [result[2]] keys = {} keys = {result[1]: value2[result[1]], **keys} migration.bulk_insertion(keys, tables) print("{} key is changed".format(key_name)) return value2 key_name = result[1] new = result[2:] value1 = set() for i in new: value1.add(i) value2[key_name] = list(value1) keys = {} keys = {key_name: value2[result[1]], **keys} migration.bulk_insertion(keys, tables) print("{} key is changed".format(key_name)) return value2
def hashes(result): key_name = result[1] command = result[0] value2 = {result[1]: {}} if command == 'hdel': if len(result) == 3: value2[result[1]] = result[2] keys_delete = {} keys_delete = {result[1]: value2[result[1]], **keys_delete} migration.bulk_deletion(keys_delete, tables) print("%s key is deleted", key_name) return value2 else: result1 = result[2:] value1 = set() for i in result1: value1.add(i) value2[key_name] = list(value1) keys_delete = {} keys_delete = {result[1]: value2[key_name], **keys_delete} migration.bulk_deletion(keys_delete, tables) print("{} key is deleted".format(key_name)) return value2 for table in tables.keys(): regex = tables[table]["regex"] if re.match(regex, key_name): query_table = tables[table]["object"]() primary_keys = migration.get_primary_key_value(tables[table], value2) where_clause_parameter = [str(query_table.__table__.c[k[5:]] == migration.bindparam(k)) for k in primary_keys.keys()] where_clause_parameter = " ".join(where_clause_parameter) stmt = query_table.__table__.select() \ .where(where_clause_parameter) conn = migration.engine.connect() res = conn.execute(stmt, **primary_keys) for hash_name in res: hash_names = hash_name[1].split(" ") if set(hash_names) == set(): break else: if len(result) == 3: value2[result[1]][result[2]] = result[3] else: new = result[2:] eff_length = len(new) wanted_parts = eff_length // 2 result1 = split_list(new, wanted_parts) for item in result1: value2[result[1]][str(item[0])] = item[1] item.insert(0, key_name) keys = {} keys = {key_name: value2[key_name], **keys} update_cont(keys, tables[table]) print("{} key is updated".format(key_name)) return value2 if len(result) == 4: value2[result[1]][result[2]] = result[3] keys = {} keys = {key_name: value2[result[1]], **keys} migration.bulk_insertion(keys, tables) print("{} key is inserted".format(key_name)) return value2 else: new = result[2:] eff_length = len(new) wanted_parts = eff_length // 2 result1 = split_list(new, wanted_parts) for item in result1: value2[result[1]][str(item[0])] = item[1] item.insert(0, key_name) keys = {} keys = {key_name: value2[result[1]], **keys} migration.bulk_insertion(keys, tables) print("{} key is inserted".format(key_name)) return value2