From f4afe0ce199d47184e23363f470b5faa7c0517be Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Thu, 28 Jan 2016 14:13:28 -0500 Subject: [PATCH] check to see if the application is running interactively (using isatty) and be a little quieter --- py25/bacpypes/consolecmd.py | 20 ++++++++++++++++---- py27/bacpypes/consolecmd.py | 20 ++++++++++++++++---- py34/bacpypes/consolecmd.py | 20 ++++++++++++++++---- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/py25/bacpypes/consolecmd.py b/py25/bacpypes/consolecmd.py index a05ee1c..e6d109b 100755 --- a/py25/bacpypes/consolecmd.py +++ b/py25/bacpypes/consolecmd.py @@ -44,8 +44,16 @@ class ConsoleCmd(cmd.Cmd, Thread, Logging): cmd.Cmd.__init__(self, stdin=stdin, stdout=stdout) Thread.__init__(self, name="ConsoleCmd") - # save the prompt and exec option - self.prompt = prompt + # check to see if this is running interactive + self.interactive = sys.__stdin__.isatty() + + # save the prompt for interactive sessions, otherwise be quiet + if self.interactive: + self.prompt = prompt + else: + self.prompt = '' + + # save the exec option self.allow_exec = allow_exec # gc counters @@ -272,9 +280,13 @@ class ConsoleCmd(cmd.Cmd, Thread, Logging): if not isinstance(err, IOError): self.stdout.write("history error: %s\n" % err) - cmd.Cmd.postloop(self) ## Clean up command completion + # clean up command completion + cmd.Cmd.postloop(self) - self.stdout.write("Exiting...\n") + if self.interactive: + self.stdout.write("Exiting...\n") + + # tell the core we have stopped core.stop() def precmd(self, line): diff --git a/py27/bacpypes/consolecmd.py b/py27/bacpypes/consolecmd.py index ae32b4f..985290b 100755 --- a/py27/bacpypes/consolecmd.py +++ b/py27/bacpypes/consolecmd.py @@ -45,8 +45,16 @@ class ConsoleCmd(cmd.Cmd, Thread, Logging): cmd.Cmd.__init__(self, stdin=stdin, stdout=stdout) Thread.__init__(self, name="ConsoleCmd") - # save the prompt and exec option - self.prompt = prompt + # check to see if this is running interactive + self.interactive = sys.__stdin__.isatty() + + # save the prompt for interactive sessions, otherwise be quiet + if self.interactive: + self.prompt = prompt + else: + self.prompt = '' + + # save the exec option self.allow_exec = allow_exec # gc counters @@ -273,9 +281,13 @@ class ConsoleCmd(cmd.Cmd, Thread, Logging): if not isinstance(err, IOError): self.stdout.write("history error: %s\n" % err) - cmd.Cmd.postloop(self) ## Clean up command completion + # clean up command completion + cmd.Cmd.postloop(self) - self.stdout.write("Exiting...\n") + if self.interactive: + self.stdout.write("Exiting...\n") + + # tell the core we have stopped core.stop() def precmd(self, line): diff --git a/py34/bacpypes/consolecmd.py b/py34/bacpypes/consolecmd.py index a2b5828..6866b6b 100755 --- a/py34/bacpypes/consolecmd.py +++ b/py34/bacpypes/consolecmd.py @@ -45,8 +45,16 @@ class ConsoleCmd(cmd.Cmd, Thread, Logging): cmd.Cmd.__init__(self, stdin=stdin, stdout=stdout) Thread.__init__(self, name="ConsoleCmd") - # save the prompt and exec option - self.prompt = prompt + # check to see if this is running interactive + self.interactive = sys.__stdin__.isatty() + + # save the prompt for interactive sessions, otherwise be quiet + if self.interactive: + self.prompt = prompt + else: + self.prompt = '' + + # save the exec option self.allow_exec = allow_exec # gc counters @@ -274,9 +282,13 @@ class ConsoleCmd(cmd.Cmd, Thread, Logging): if not isinstance(err, IOError): self.stdout.write("history error: %s\n" % err) - cmd.Cmd.postloop(self) ## Clean up command completion + # clean up command completion + cmd.Cmd.postloop(self) - self.stdout.write("Exiting...\n") + if self.interactive: + self.stdout.write("Exiting...\n") + + # tell the core we have stopped core.stop() def precmd(self, line):