Mercurial > p > roundup > code
comparison roundup/admin.py @ 7795:d7d68da9878f
save roundup-admin history between sessions.
Also load ~/.roundup_admin_rlrc (rlrc readline run commands) file to
set history-size persistently, allow user to use vi mode etc.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 10 Mar 2024 13:44:13 -0400 |
| parents | ac2c034542e6 |
| children | 5f3b49bb7742 |
comparison
equal
deleted
inserted
replaced
| 7794:1632bdbfbef6 | 7795:d7d68da9878f |
|---|---|
| 112 self.force = None | 112 self.force = None |
| 113 self.settings = { | 113 self.settings = { |
| 114 'display_header': False, | 114 'display_header': False, |
| 115 'display_protected': False, | 115 'display_protected': False, |
| 116 'indexer_backend': "as set in config.ini", | 116 'indexer_backend': "as set in config.ini", |
| 117 'history_length': -1, | |
| 117 '_reopen_tracker': False, | 118 '_reopen_tracker': False, |
| 118 'savepoint_limit': self._default_savepoint_setting, | 119 'savepoint_limit': self._default_savepoint_setting, |
| 119 'show_retired': "no", | 120 'show_retired': "no", |
| 120 '_retired_val': False, | 121 '_retired_val': False, |
| 121 'verbose': False, | 122 'verbose': False, |
| 2085 def interactive(self): | 2086 def interactive(self): |
| 2086 """Run in an interactive mode | 2087 """Run in an interactive mode |
| 2087 """ | 2088 """ |
| 2088 print(_('Roundup %s ready for input.\nType "help" for help.') | 2089 print(_('Roundup %s ready for input.\nType "help" for help.') |
| 2089 % roundup_version) | 2090 % roundup_version) |
| 2091 | |
| 2092 initfile = os.path.join(os.path.expanduser("~"), | |
| 2093 ".roundup_admin_rlrc") | |
| 2094 histfile = os.path.join(os.path.expanduser("~"), | |
| 2095 ".roundup_admin_history") | |
| 2096 | |
| 2090 try: | 2097 try: |
| 2091 import readline # noqa: F401 | 2098 import readline # noqa: F401 |
| 2099 readline.read_init_file(initfile) | |
| 2100 try: | |
| 2101 readline.read_history_file(histfile) | |
| 2102 except FileNotFoundError: | |
| 2103 # no history file yet | |
| 2104 pass | |
| 2105 | |
| 2106 # Default history length is unlimited. | |
| 2107 # Set persistently in readline init file | |
| 2108 # Pragma history_length allows setting on a per | |
| 2109 # invocation basis at startup | |
| 2110 if self.settings['history_length'] != -1: | |
| 2111 readline.set_history_length( | |
| 2112 self.settings['history_length']) | |
| 2092 except ImportError: | 2113 except ImportError: |
| 2114 readline = None | |
| 2093 print(_('Note: command history and editing not available')) | 2115 print(_('Note: command history and editing not available')) |
| 2094 | 2116 |
| 2095 while 1: | 2117 while 1: |
| 2096 try: | 2118 try: |
| 2097 command = self.my_input('roundup> ') | 2119 command = self.my_input('roundup> ') |
| 2110 # exit.. check for transactions | 2132 # exit.. check for transactions |
| 2111 if self.db and self.db_uncommitted: | 2133 if self.db and self.db_uncommitted: |
| 2112 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? ')) | 2134 commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? ')) |
| 2113 if commit and commit[0].lower() == 'y': | 2135 if commit and commit[0].lower() == 'y': |
| 2114 self.db.commit() | 2136 self.db.commit() |
| 2137 | |
| 2138 # looks like histfile is saved with mode 600 | |
| 2139 if readline: | |
| 2140 readline.write_history_file(histfile) | |
| 2115 return 0 | 2141 return 0 |
| 2116 | 2142 |
| 2117 def main(self): # noqa: PLR0912, PLR0911 | 2143 def main(self): # noqa: PLR0912, PLR0911 |
| 2118 try: | 2144 try: |
| 2119 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdP:sS:vV') | 2145 opts, args = getopt.getopt(sys.argv[1:], 'i:u:hcdP:sS:vV') |
