From f996ecdf6eac730a1f81ad2045897a242d4687e5 Mon Sep 17 00:00:00 2001 From: Sourcery AI Date: Mon, 20 Feb 2023 07:10:37 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- db-topology.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/db-topology.py b/db-topology.py index 73b80be..c3c042d 100755 --- a/db-topology.py +++ b/db-topology.py @@ -13,29 +13,27 @@ def find_top(host, port): - g.add_node(host + ':' + port) + g.add_node(f'{host}:{port}') try: cnx = mysql.connector.connect( host=host, port=port, user=user, password=password) cursor = cnx.cursor() query = ( "show slave status;select host from INFORMATION_SCHEMA.PROCESSLIST where command = 'Binlog Dump';show slave hosts;") - l = [] - for result in cursor.execute(query, multi=True): - l.append(result.fetchall()) + l = [result.fetchall() for result in cursor.execute(query, multi=True)] # print(l[0]) if l[1] != []: - for k in range(0, len(l[1])): + for k in range(len(l[1])): slave_host = str(l[1][k][0].split(':')[0]) slave_port = str(l[2][k][2]) - g.add_node(slave_host + ':' + slave_port) - g.add_edge(slave_host + ':' + slave_port, host + ':' + port) + g.add_node(f'{slave_host}:{slave_port}') + g.add_edge(f'{slave_host}:{slave_port}', f'{host}:{port}') find_top(slave_host, slave_port) if l[0] != []: master_host = str(l[0][0][1]) master_port = str(l[0][0][3]) - if master_host+':'+master_port not in g: + if f'{master_host}:{master_port}' not in g: find_top(master_host, master_port) except mysql.connector.Error as err: