History Backend JSON – xonsh.history.json
¶
Implements JSON version of xonsh history backend.
-
class
xonsh.history.json.
JsonCommandField
(field, hist, default=None)[source]¶ A field in the ‘cmds’ portion of history.
Represents a field in the ‘cmds’ portion of history.
Will query the buffer for the relevant data, if possible. Otherwise it will lazily acquire data from the file.
Parameters: field : str
The name of the field to query.
hist : History object
The history object to query.
default : optional
The default value to return if key is not present.
-
class
xonsh.history.json.
JsonHistory
(filename=None, sessionid=None, buffersize=100, gc=True, **meta)[source]¶ Xonsh history backend implemented with JSON files.
JsonHistory implements two extra actions:
diff
, andreplay
.Represents a xonsh session’s history as an in-memory buffer that is periodically flushed to disk.
Parameters: filename : str, optional
Location of history file, defaults to
$XONSH_DATA_DIR/xonsh-{sessionid}.json
.sessionid : int, uuid, str, optional
Current session identifier, will generate a new sessionid if not set.
buffersize : int, optional
Maximum buffersize in memory.
meta : optional
Top-level metadata to store along with the history. The kwargs ‘cmds’ and ‘sessionid’ are not allowed and will be overwritten.
gc : bool, optional
Run garbage collector flag.
-
all_items
(newest_first=False, **kwargs)[source]¶ Returns all history as found in XONSH_DATA_DIR.
yield format: {‘inp’: cmd, ‘rtn’: 0, …}
-
append
(cmd)[source]¶ Appends command to history. Will periodically flush the history to file.
Parameters: cmd : dict
This dict contains information about the command that is to be added to the history list. It should contain the keys
inp
,rtn
andts
. These key names mirror the same names defined as instance variables in theHistoryEntry
class.Returns: hf : JsonHistoryFlusher or None
The thread that was spawned to flush history
-
flush
(at_exit=False)[source]¶ Flushes the current command buffer to disk.
Parameters: at_exit : bool, optional
Whether the JsonHistoryFlusher should act as a thread in the background, or execute immediately and block.
Returns: hf : JsonHistoryFlusher or None
The thread that was spawned to flush history
-
-
class
xonsh.history.json.
JsonHistoryFlusher
(filename, buffer, queue, cond, at_exit=False, *args, **kwargs)[source]¶ Flush shell history to disk periodically.
Thread for flushing history.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-
-
class
xonsh.history.json.
JsonHistoryGC
(wait_for_shell=True, size=None, *args, **kwargs)[source]¶ Shell history garbage collection.
Thread responsible for garbage collecting old history.
May wait for shell (and for xonshrc to have been loaded) to start work.
-
files
(only_unlocked=False)[source]¶ Find and return the history files. Optionally locked files may be excluded.
This is sorted by the last closed time. Returns a list of (timestamp, number of cmds, file name) tuples.
-
run
()[source]¶ Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
-