I created kaa/vfs and added to vfs/src/db.py a cleaned up version of
what I emailed here yesterday.  See test/testdb.py for a demo.

The main change I made to the code was removing the whole notion of
directories.  Instead, everything is an object, and any object can be a
parent of any other object.  So you would register a "dir" object, and
create other objects as children.  (Actually, the "dir" type is
currently created by default.  The DB probably shouldn't do that, but
rather the VFS should.)  So:

   db.register_object_type_attrs("dir")
   db.register_object_type_attrs("image")
   
   dir = db.add_object(("type", "/home/freevo/mp3"))
   db.add_object(("image", "foobar.jpg"), parent = ("dir", dir["id"]))

Objects are represented by a tuple (type, name) when adding, and (type,
id) when updating, where type is the type name of the object ("dir",
"image", etc.)  Parents are always represented by a (type, id) tuple.  A
more friendly API can be added at the VFS layer, so the user can
reference files by name (and not have to worry about ids), and suitable
caching would occur at that level.

You can query like this:

   # list all files in the directory
   results = db.query(parent = ("dir", dir["id"]))
   # Generate a very quick sorted list of filenames:
   files = db.list_query_results_names(results)
   # Generate full "normalized" list of dicts.  (Slow, of course.)
   files = db.normalize_query_results(results)

Adding directories like I did above isn't really how we'd want to do it.
It makes sense to make full use of the parent id, so the VFS would
actually create separate objects for each element in the path (i.e. /,
home, freevo, and mp3 "dir" objects, with appropriate parent ids set).

The keyword code still needs to be added.  That's not so trivial, so I
won't have time to do it for a while.  But the basic idea is still
there.

So this should be something to get us started.  Even if we end up going
in a different direction, at least there's movement on this module. :)

Jason.

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to