Skip to content

Commit 719af32

Browse files
author
Olivier Roques
committed
Format code and add pycodestyle setup
1 parent f3285fd commit 719af32

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pycodestyle]
2+
ignore = E701

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="sshcontroller",
8-
version="1.2",
8+
version="1.3",
99
author="Olivier Roques",
1010
author_email="[email protected]",
1111
description="A package to easily run SSH commands",

sshcontroller/sshcontroller.py

+11-25
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def __init__(
7676
else:
7777
index = len(self.keys) if key_password is None else 0
7878
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")
8280

8381
def connect(self):
8482
try:
@@ -123,8 +121,7 @@ def _run_until_event(
123121
channel = self.transport.open_session()
124122
channel.settimeout(2)
125123
channel.set_combine_stderr(combine_stderr)
126-
if shell:
127-
channel.get_pty()
124+
if shell: channel.get_pty()
128125
channel.exec_command(command)
129126

130127
if not display and not capture:
@@ -134,19 +131,13 @@ def _run_until_event(
134131
try:
135132
raw_data = channel.recv(self.nb_bytes)
136133
except socket.timeout:
137-
if stop_event.is_set():
138-
break
134+
if stop_event.is_set(): break
139135
continue
140-
141-
if not raw_data:
142-
break
136+
if not raw_data: break
143137
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
150141

151142
channel.close()
152143

@@ -168,8 +159,7 @@ def _run_until_exit(
168159
channel = self.transport.open_session()
169160
channel.settimeout(timeout)
170161
channel.set_combine_stderr(combine_stderr)
171-
if shell:
172-
channel.get_pty()
162+
if shell: channel.get_pty()
173163
channel.exec_command(command)
174164

175165
try:
@@ -178,13 +168,10 @@ def _run_until_exit(
178168
else:
179169
while True:
180170
raw_data = channel.recv(self.nb_bytes)
181-
if not raw_data:
182-
break
171+
if not raw_data: break
183172
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
188175
except socket.timeout:
189176
logging.warning(f"Timeout after {timeout}s")
190177
exit_code = 1
@@ -235,7 +222,6 @@ def wrapper(*args, **kwargs):
235222
if not self.transport.is_authenticated():
236223
logging.error("SSH session is not ready")
237224
return
238-
239225
sftp_channel = SFTPController.from_transport(self.transport)
240226
r = getattr(sftp_channel, target)(*args, **kwargs)
241227
sftp_channel.close()

0 commit comments

Comments
 (0)