preftree 0.3 released

D

David Fraser

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
 
D

Donald 'Paddy' McCarthy

Wilk said:
thanks, it look a lot like yaml... Don't you think it could be a layer
on top of yaml ?
The example shows string, integers and (nested) dictionary types. I
presume floating point would be obvious, and is included but what about
lists?

Cheers, Pad.
 
D

David Fraser

Wilk said:
thanks, it look a lot like yaml... Don't you think it could be a layer
on top of yaml ?
I'd forgotten about yaml, it's pretty cool.
This is a bit simpler than yaml (and has less features) and meets our
current needs, but yaml is good too...
I'm not sure if it could be put on top of yaml as that may be more work
than doing it directly.

David
 
D

David Fraser

Donald said:
The example shows string, integers and (nested) dictionary types. I
presume floating point would be obvious, and is included but what about
lists?

Floating point? Never! :) I should add that.
Lists aren't included (which is something yaml does with different
syntax), but the preftree approach would be to just have a number of
elements. The inspiration for preftree was from the Mozilla prefs, where
for example a list of mail accounts would contain account1, account2 etc.
What we need to do is make it easier to iterate over elements at a point
in a tree.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,651
Latest member
VeraPiw932

Latest Threads

Top