5
5
from .utils import user_choice
6
6
7
7
8
- def set_password (new_password = None , connection = None , update_config = None ): # pragma: no cover
8
+ def set_password (
9
+ new_password = None , connection = None , update_config = None
10
+ ): # pragma: no cover
9
11
connection = conn () if connection is None else connection
10
12
if new_password is None :
11
- new_password = getpass (' New password: ' )
12
- confirm_password = getpass (' Confirm password: ' )
13
+ new_password = getpass (" New password: " )
14
+ confirm_password = getpass (" Confirm password: " )
13
15
if new_password != confirm_password :
14
- print (' Failed to confirm the password! Aborting password change.' )
16
+ print (" Failed to confirm the password! Aborting password change." )
15
17
return
16
18
connection .query ("SET PASSWORD = PASSWORD('%s')" % new_password )
17
- print (' Password updated.' )
19
+ print (" Password updated." )
18
20
19
- if update_config or (update_config is None and user_choice ('Update local setting?' ) == 'yes' ):
20
- config ['database.password' ] = new_password
21
+ if update_config or (
22
+ update_config is None and user_choice ("Update local setting?" ) == "yes"
23
+ ):
24
+ config ["database.password" ] = new_password
21
25
config .save_local (verbose = True )
22
26
23
27
@@ -40,24 +44,32 @@ def kill(restriction=None, connection=None, order_by=None): # pragma: no cover
40
44
connection = conn ()
41
45
42
46
if order_by is not None and not isinstance (order_by , str ):
43
- order_by = ',' .join (order_by )
47
+ order_by = "," .join (order_by )
44
48
45
- query = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()' + (
46
- "" if restriction is None else ' AND (%s)' % restriction ) + (
47
- ' ORDER BY %s' % (order_by or 'id' ))
49
+ query = (
50
+ "SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()"
51
+ + ("" if restriction is None else " AND (%s)" % restriction )
52
+ + (" ORDER BY %s" % (order_by or "id" ))
53
+ )
48
54
49
55
while True :
50
- print (' ID USER HOST STATE TIME INFO' )
51
- print ('+--+ +----------+ +-----------+ +-----------+ +-----+' )
52
- cur = ({k .lower (): v for k , v in elem .items ()}
53
- for elem in connection .query (query , as_dict = True ))
56
+ print (" ID USER HOST STATE TIME INFO" )
57
+ print ("+--+ +----------+ +-----------+ +-----------+ +-----+" )
58
+ cur = (
59
+ {k .lower (): v for k , v in elem .items ()}
60
+ for elem in connection .query (query , as_dict = True )
61
+ )
54
62
for process in cur :
55
63
try :
56
- print ('{id:>4d} {user:<12s} {host:<12s} {state:<12s} {time:>7d} {info}' .format (** process ))
64
+ print (
65
+ "{id:>4d} {user:<12s} {host:<12s} {state:<12s} {time:>7d} {info}" .format (
66
+ ** process
67
+ )
68
+ )
57
69
except TypeError :
58
70
print (process )
59
71
response = input ('process to kill or "q" to quit > ' )
60
- if response == 'q' :
72
+ if response == "q" :
61
73
break
62
74
if response :
63
75
try :
@@ -66,9 +78,9 @@ def kill(restriction=None, connection=None, order_by=None): # pragma: no cover
66
78
pass # ignore non-numeric input
67
79
else :
68
80
try :
69
- connection .query (' kill %d' % pid )
81
+ connection .query (" kill %d" % pid )
70
82
except pymysql .err .InternalError :
71
- print (' Process not found' )
83
+ print (" Process not found" )
72
84
73
85
74
86
def kill_quick (restriction = None , connection = None ):
@@ -86,13 +98,17 @@ def kill_quick(restriction=None, connection=None):
86
98
if connection is None :
87
99
connection = conn ()
88
100
89
- query = 'SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()' + (
90
- "" if restriction is None else ' AND (%s)' % restriction )
101
+ query = (
102
+ "SELECT * FROM information_schema.processlist WHERE id <> CONNECTION_ID()"
103
+ + ("" if restriction is None else " AND (%s)" % restriction )
104
+ )
91
105
92
- cur = ({k .lower (): v for k , v in elem .items ()}
93
- for elem in connection .query (query , as_dict = True ))
106
+ cur = (
107
+ {k .lower (): v for k , v in elem .items ()}
108
+ for elem in connection .query (query , as_dict = True )
109
+ )
94
110
nkill = 0
95
111
for process in cur :
96
- connection .query (' kill %d' % process ['id' ])
112
+ connection .query (" kill %d" % process ["id" ])
97
113
nkill += 1
98
114
return nkill
0 commit comments