Skip to content

Commit 70224b6

Browse files
authored
Merge pull request #5 from makermelissa/master
Can get output returned from run_command
2 parents 3e8e9b0 + f219986 commit 70224b6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

adafruit_shell.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,34 @@ def select_n(message, selections):
5959
)
6060
return prompt.options(message, options)
6161

62-
def run_command(self, cmd, suppress_message=False):
62+
def run_command(self, cmd, suppress_message=False, return_output=False):
6363
"""
6464
Run a shell command and show the output as it runs
6565
"""
6666
proc = subprocess.Popen(
6767
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
6868
)
69+
full_output = ""
6970
while True:
7071
output = proc.stdout.readline()
7172
if len(output) == 0 and proc.poll() is not None:
7273
break
73-
if output and not suppress_message:
74-
self.info(output.decode("utf-8").strip())
74+
if output:
75+
decoded_output = output.decode("utf-8").strip()
76+
if not suppress_message:
77+
self.info(decoded_output)
78+
full_output += decoded_output
7579
r = proc.poll()
7680
if r == 0:
81+
if return_output:
82+
return full_output
7783
return True
7884

7985
err = proc.stderr.read()
8086
if not suppress_message:
8187
self.error(err.decode("utf-8"))
88+
if return_output:
89+
return full_output
8290
return False
8391

8492
def info(self, message):
@@ -366,6 +374,11 @@ def write_text_file(self, path, content, append=True):
366374
service_file.write(content)
367375
service_file.close()
368376

377+
@staticmethod
378+
def is_python3():
379+
"Check if we are running Python 3 or later"
380+
return int(platform.python_version()[0]) >= 3
381+
369382
@staticmethod
370383
def is_linux():
371384
"""

0 commit comments

Comments
 (0)