| 42 | return [] |
| 43 | |
| 44 | def store_string(self, string): |
| 45 | history = {'version': self.HISTORY_VERSION, 'commands': []} |
| 46 | try: |
| 47 | if os.path.exists(self.filename): |
| 48 | with open(self.filename) as f: |
| 49 | history = json.load(f) |
| 50 | elif not os.path.exists(os.path.dirname(self.filename)): |
| 51 | os.makedirs(os.path.dirname(self.filename)) |
| 52 | history['commands'].append(string) |
| 53 | history['commands'] = history['commands'][-self._max_commands :] |
| 54 | with open(self.filename, 'w') as f: |
| 55 | json.dump(history, f) |
| 56 | try: |
| 57 | os.chmod(self.filename, 0o600) |
| 58 | except OSError as e: |
| 59 | LOG.debug('Unable to set file permissions for autoprompt history file: %s', e) |
| 60 | except Exception as e: |
| 61 | LOG.debug('Unable to save autoprompt history (check file permissions): %s', e) |
| 62 | |
| 63 | |
| 64 | class HistoryCompleter(Completer): |