[PATCH 6/8] Don't use readline unless isatty

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Importing readline emits escape sequences to stdout. We want to avoid this
when output is not to a tty.

Signed-off-by: Andy Grover <agrover@xxxxxxxxxx>
---
 configshell/shell.py |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/configshell/shell.py b/configshell/shell.py
index ab32f8e..e39ec9c 100644
--- a/configshell/shell.py
+++ b/configshell/shell.py
@@ -17,7 +17,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import os
 import sys
-import readline
 import simpleparse.parser
 import simpleparse.dispatchprocessor
 
@@ -44,6 +43,12 @@ except Exception:
     # In a thread, this fails
     pass
 
+if sys.stdout.isatty():
+    import readline
+    tty=True
+else:
+    tty=False
+
 class ConfigShell(object):
     '''
     This is a simple CLI command interpreter that can be used both in
@@ -114,7 +119,9 @@ class ConfigShell(object):
         self._exit = False
 
         self._parser = simpleparse.parser.Parser(self.grammar, root='line')
-        readline.set_completer_delims('\t\n ~!#$^&()[{]}\|;\'",?')
+
+        if tty:
+            readline.set_completer_delims('\t\n ~!#$^&()[{]}\|;\'",?')
 
         self.log = log.Log()
 
@@ -135,7 +142,7 @@ class ConfigShell(object):
                                      + "command history will not be saved.")
                     self._save_history = False
 
-            if os.path.isfile(self._cmd_history):
+            if os.path.isfile(self._cmd_history) and tty:
                 try:
                     readline.read_history_file(self._cmd_history)
                 except IOError:
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux