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
capacityint, a limit on the number of items in the history
sessionSession instance
tagstr, a unique tag to identify the history
unversionedbool, optional, defaults to True
auto_savebool, 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(self)

Experimental API . Remove all items

dequeue(self, _skip_save=False)

Experimental API . Remove and return oldest item

enqueue(self, value)

Experimental API . Add newest item

extend(self, iterable)

Experimental API . Add newest items

replace(self, iterable)

Experimental API . Replace current items

save(self)

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
capacityint, a limit on the number of items in the history
sessionSession instance
tagstr, a unique tag to identify the history
unversionedbool, optional, defaults to True
auto_savebool, 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(self, item)

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

Parameters
itemsimple type suitable for Python’s JSON module.
save(self)

Experimental API . Save set to history file.

class ObjectHistory(tag, unversioned=True)

Bases: object

Maintain an object in application’s history on disk.

Parameters
sessionSession instance
tagstr, a unique tag to identify the cache
unversionedbool, optional, defaults to False

Notes

Uses JSON to serialize and deserialize history object.

load(self)

Experimental API . Return deserialized object from history file.

save(self, obj)

Experimental API . Serialize object into history file.

Parameters
objobject

The object to save.