history: Application history support

This module provides support for caching information across application invocations. In particular, it is useful for command and file history.

History files are kept in an application user’s cache directory, so there is the assumption that they can be removed and the application will still work.

class FIFOHistory(capacity, session, tag, unversioned=True, auto_save=True)

Bases: object

A fixed capacity FIFO queue with backing store.

Parameters:
capacity : int, a limit on the number of items in the history
session : Session instance
tag : str, a unique tag to identify the history
unversioned : bool, optional, defaults to True
auto_save : bool, optional, defaults to True

If unversioned is true, then the history is for all versions of application. If auto_save is true, then the history is flushed to disk everyime it is updated.

Notes

Iterating returns oldest first.

clear()

Experimental API . Remove all items

dequeue(_skip_save=False)

Experimental API . Remove and return oldest item

enqueue(value)

Experimental API . Add newest item

extend(iterable)

Experimental API . Add newest items

replace(iterable)

Experimental API . Replace current items

save()

Experimental API . Save to history file.

class LRUSetHistory(capacity, session, tag, unversioned=True, auto_save=True)

Bases: OrderedSet

A fixed capacity LRU set with backing store.

Saves and restores a set of data from a history file. Use the add() method to put items into the set and to update it. The last member of the set is the most recent. ALl of the normal set methods are supported as well.

Parameters:
capacity : int, a limit on the number of items in the history
session : Session instance
tag : str, a unique tag to identify the history
unversioned : bool, optional, defaults to True
auto_save : bool, optional, defaults to True

If unversioned is true, then the history is for all versions of application. If auto_save is true, then the history is flushed to disk everyime it is updated.

add(item)

Experimental API . Add item to set and make it the most recent.

Parameters:
item : simple type suitable for Python’s JSON module.
save()

Experimental API . Save set to history file.

class ObjectHistory(tag, unversioned=True)

Bases: object

Maintain an object in application’s history on disk.

Parameters:
session : Session instance
tag : str, a unique tag to identify the cache
unversioned : bool, optional, defaults to False

Notes

Uses JSON to serialize and deserialize history object.

load()

Experimental API . Return deserialized object from history file.

save(obj)

Experimental API . Serialize object into history file.

Parameters:
obj : object

The object to save.