cliutils 0.1.3 released: Persistence, home directories

This release of cliutils adds a few handy items. The new persistence module provides a function (storage_dir) that will, on Windows or *nix, find a directory where settings files should be stored (namely, the roaming Application Data directory on Windows, or the current user's home directory on *nix). Not too complex, but it removes a bit of overhead in locating the proper storage path. Also handy for creating directories; if the result doesn't exist, it'll be created.

The persistence module also provides a function that uses the inimitable shelve module to create a persistent dictionary, getting its path from storage_dir. This lets one create very simple databases on the fly for storing settings and whatnot, like:

>>> db('.myscript')

Since the dictionary is saved whenever changed, it can be used just like a regular dictionary, only persistent. I've found this very useful.

Finally, the persistence module provides a simple dictionary-like interface to ConfigParser instances, again getting a path through storage_dir:

>>> import tempfile; filename = tempfile.mkstemp()[1]
>>> cfg = config(filename)
>>> cfg['sec1']['option2'] = 75
>>> cfg['sec2']['option1'] = "Some String"
>>> cfg['sec2']['option2'] = "Another value"
>>> f = file(filename)
>>> print
option2 = 75

option2 = Another value
option1 = Some String

Lastly, at the suggestion of a commenter, the logged decorator has been renamed to the more accurate redirect. Also, log_decorator has been deprecated, since it was really just a synonym of logged.

Download from Google Code or pypi. Upgrade or install anew with:

easy_install -U cliutils

API docs are here.


Post a Comment