preftree 0.3 released

David Fraser davidf at sjsoft.com
Fri May 28 07:57:54 EDT 2004


Following up on a promise in the Config discussion ...

preftree has been released under the Python license.
You can get version 0.3 from 
http://davidf.sjsoft.com/files/preftree-0.3.tar.gz

The README is below... any questions or feedback welcome, a more well 
packaged release can be done later.

David


prefstree README

prefstree is a simple python package for managing application preferences.

Overview
--------

- prefs are stored in a text format
- prefs are in a hierarchical tree
- you can parse this tree, and get a object tree out of it
- the modified tree can be stored back into the file
- we try to make it pythonic...

Hello Prefs
-----------

Given the prefs file hello.prefs:

hello:
   firstrun = 1
   greet = "world"

the code:

from preftree import prefs
helloprefs = prefs.PrefsParser()
helloprefs.parse(open('hello.prefs', 'r'))
print "Hello %d" % helloprefs.hello.greet
helloprefs.hello.firstrun = 0
open('hello.prefs', 'w').write(helloprefs.getsource())

pref file format
----------------

this is an attempt to be python
pref names are "." separated
you can use them straight:

a.b.c = "hello"
a.b.d = "goodbye"
f.g = "someone"

or you can declare a node and indent children

a.b:
   c = "hello"
   d = "goodbye"

f.g = "someone"

you can also make a value/node based on another value/node:

a.q = a.b:
   c = "yes"
   e = f.g

this will result in the following values:

a.b.c = "hello"
a.b.d = "goodbye"
a.q.c = "yes"
a.q.d = "goodbye"
a.q.e = "someone"
f.g = "someone"

saving back to a file attempts to preserve sensibility and human 
readability without modifying unmodified prefs



More information about the Python-list mailing list