Skip to content

Commit 30f9fea

Browse files
committed
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.
1 parent 33bc168 commit 30f9fea

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ Features:
124124
dump_dbm_sessions_db.py, contributors.py (John Rouillard)
125125
- roundup/msgfile.py can now be called as 'python msgfmt.py de.po de.mo'
126126
to compile a translation file if msgfmt is missing. (John Rouillard)
127+
- save roundup-admin history between sessions. Load
128+
~/.roundup_admin_rlrc file to set history-size persistently. Add
129+
pragma history_length to override for a session. (John Rouillard)
127130

128131

129132
2023-07-13 2.3.0

doc/admin_guide.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,33 @@ and feed it to roundup-admin on standard input. E.G.
14071407

14081408
.. index:: ! roundup-admin; usage in scripts
14091409

1410+
Using Interactively
1411+
-------------------
1412+
1413+
You can edit the command line using left/right arrow keys to move the
1414+
cursor. Using the up/down arrow keys moves among commands. It will
1415+
save your commands between roundup-admin sessions. This is supported
1416+
on Unix/Linux and Mac's. On windows you should install the pyreadline3
1417+
package (see `installation documentation`_).
1418+
1419+
Using the ``history_length`` pragma you can set the saved history size
1420+
for just one session.
1421+
1422+
You can add initialization commands to ``~/.roundup_admin_rlrc``. It
1423+
will be loaded when roundup-admin starts. This is the mechanism to
1424+
persistently set the number of history commands, change editing modes
1425+
(Vi vs. Emacs). Note that redefining the history file will not work.
1426+
1427+
If you are using GNU readline, ``set history-size 10``. If your
1428+
installation uses libedit (macs), it should be possible to
1429+
persistently set the history size using ``history size
1430+
10``. Pyreadline3 can set history length using
1431+
``history_length(10)``. See the older documentation for example syntax:
1432+
https://pythonhosted.org/pyreadline/usage.html.persistently.
1433+
1434+
History is saved to the file ``.roundup_admin_history`` in your home
1435+
directory (for windows usually ``\Users\<username>``.
1436+
14101437
Using with the shell
14111438
--------------------
14121439

roundup/admin.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def __init__(self):
114114
'display_header': False,
115115
'display_protected': False,
116116
'indexer_backend': "as set in config.ini",
117+
'history_length': -1,
117118
'_reopen_tracker': False,
118119
'savepoint_limit': self._default_savepoint_setting,
119120
'show_retired': "no",
@@ -2087,9 +2088,30 @@ def interactive(self):
20872088
"""
20882089
print(_('Roundup %s ready for input.\nType "help" for help.')
20892090
% 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+
20902097
try:
20912098
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'])
20922113
except ImportError:
2114+
readline = None
20932115
print(_('Note: command history and editing not available'))
20942116

20952117
while 1:
@@ -2112,6 +2134,10 @@ def interactive(self):
21122134
commit = self.my_input(_('There are unsaved changes. Commit them (y/N)? '))
21132135
if commit and commit[0].lower() == 'y':
21142136
self.db.commit()
2137+
2138+
# looks like histfile is saved with mode 600
2139+
if readline:
2140+
readline.write_history_file(histfile)
21152141
return 0
21162142

21172143
def main(self): # noqa: PLR0912, PLR0911

share/man/man1/roundup-admin.1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,30 @@ merged/updated config file is written to \fI<filename>\fP.
291291
Commands may be abbreviated as long as the abbreviation
292292
matches only one command, e.g. l == li == lis == list.
293293

294+
.SH READLINE SUPPORT
295+
296+
You can edit the command line and interact with history in
297+
roundup-admin's interactive mode. On Linux like systems, GNU Readline
298+
is required. On Mac's libedit can be used as well. On Windows
299+
pyreadline3 is required. See:
300+
https://docs.python.org/3/library/readline.html for details on
301+
readline.
302+
303+
Roundup-admin will save the history between roundup-admin
304+
sessions. The commands are saved to the \fB.roundup_admin_history\fP
305+
file in the user's home directory. You can set the pragma
306+
\fBhistory_length\fP on the roundup-admin command line to change the
307+
amount of available and stored history for the session.
308+
309+
If you are using GNU readline, you can persistently change the history
310+
size by adding: \fBset history-size 100\fP to the init file
311+
\fB.roundup_admin_rlrc\fP located in the user's home directory.
312+
313+
Mac users using libedit should be able to persistently save history
314+
and set the history size by adding \fBhistory size 100\fP.
315+
316+
Users of pyreadline3 can use: \fBhistory_length(100)\fP.
317+
294318
.SH SECURITY NOTES
295319

296320
The \fB-u user\fP setting does not currently operate like a

0 commit comments

Comments
 (0)