@@ -76,9 +76,7 @@ def __init__(
76
76
else :
77
77
index = len (self .keys ) if key_password is None else 0
78
78
self .keys .insert (index , key )
79
-
80
- if not self .keys :
81
- logging .error ("No valid key found" )
79
+ if not self .keys : logging .error ("No valid key found" )
82
80
83
81
def connect (self ):
84
82
try :
@@ -123,8 +121,7 @@ def _run_until_event(
123
121
channel = self .transport .open_session ()
124
122
channel .settimeout (2 )
125
123
channel .set_combine_stderr (combine_stderr )
126
- if shell :
127
- channel .get_pty ()
124
+ if shell : channel .get_pty ()
128
125
channel .exec_command (command )
129
126
130
127
if not display and not capture :
@@ -134,19 +131,13 @@ def _run_until_event(
134
131
try :
135
132
raw_data = channel .recv (self .nb_bytes )
136
133
except socket .timeout :
137
- if stop_event .is_set ():
138
- break
134
+ if stop_event .is_set (): break
139
135
continue
140
-
141
- if not raw_data :
142
- break
136
+ if not raw_data : break
143
137
data = raw_data .decode ("utf-8" )
144
- if display :
145
- print (data , end = '' )
146
- if capture :
147
- output += data
148
- if stop_event .is_set ():
149
- break
138
+ if display : print (data , end = '' )
139
+ if capture : output += data
140
+ if stop_event .is_set (): break
150
141
151
142
channel .close ()
152
143
@@ -168,8 +159,7 @@ def _run_until_exit(
168
159
channel = self .transport .open_session ()
169
160
channel .settimeout (timeout )
170
161
channel .set_combine_stderr (combine_stderr )
171
- if shell :
172
- channel .get_pty ()
162
+ if shell : channel .get_pty ()
173
163
channel .exec_command (command )
174
164
175
165
try :
@@ -178,13 +168,10 @@ def _run_until_exit(
178
168
else :
179
169
while True :
180
170
raw_data = channel .recv (self .nb_bytes )
181
- if not raw_data :
182
- break
171
+ if not raw_data : break
183
172
data = raw_data .decode ("utf-8" )
184
- if display :
185
- print (data , end = '' )
186
- if capture :
187
- output += data
173
+ if display : print (data , end = '' )
174
+ if capture : output += data
188
175
except socket .timeout :
189
176
logging .warning (f"Timeout after { timeout } s" )
190
177
exit_code = 1
@@ -235,7 +222,6 @@ def wrapper(*args, **kwargs):
235
222
if not self .transport .is_authenticated ():
236
223
logging .error ("SSH session is not ready" )
237
224
return
238
-
239
225
sftp_channel = SFTPController .from_transport (self .transport )
240
226
r = getattr (sftp_channel , target )(* args , ** kwargs )
241
227
sftp_channel .close ()
0 commit comments