Set up history if readline is available
( cls )
| 73 | |
| 74 | @classmethod |
| 75 | def initReadline( cls ): |
| 76 | "Set up history if readline is available" |
| 77 | # Only set up readline once to prevent multiplying the history file |
| 78 | if cls.readlineInited: |
| 79 | return |
| 80 | cls.readlineInited = True |
| 81 | try: |
| 82 | # pylint: disable=import-outside-toplevel |
| 83 | from readline import ( read_history_file, write_history_file, |
| 84 | set_history_length ) |
| 85 | except ImportError: |
| 86 | pass |
| 87 | else: |
| 88 | history_path = os.path.expanduser( '~/.mininet_history' ) |
| 89 | if os.path.isfile( history_path ): |
| 90 | read_history_file( history_path ) |
| 91 | set_history_length( 1000 ) |
| 92 | |
| 93 | def writeHistory(): |
| 94 | "Write out history file" |
| 95 | try: |
| 96 | write_history_file( history_path ) |
| 97 | except IOError: |
| 98 | # Ignore probably spurious IOError |
| 99 | pass |
| 100 | atexit.register( writeHistory ) |
| 101 | |
| 102 | def run( self ): |
| 103 | "Run our cmdloop(), catching KeyboardInterrupt" |