Updates This Week to the Sugar Almanac - Using the Datastore and More
tomeu at tomeuvizoso.net
Wed Jun 25 04:28:00 EDT 2008
Hi Faisal, some answers below:
2008/6/24 Faisal Anwar <fanwar at mediamods.com>:
> ?? Is there a specific reason why there isn't a "set()" method in the
> datastore.DSMetadata class? Shouldn't people be given standard accessors and
> mutators to work with this code. This is especially confusing because it
> seems there is presently a "get()" method, but the set() method does not
> exist (so the abstraction is completely different based on whether you are
> getting or setting data). d
That class is to be used in the same way as dictionaries in python, so
the API mimics that. By implementing __getitem__, __setitem__ and
get(), the user can do the following:
obj.metadata['my-property'] = 'blah blah'
print obj.metadata.get('my-property', 'N/A')
> ?? Several things that are currently documented at
> http://wiki.laptop.org/go/Low-level_Activity_API#Keeping_and_Resuming are
> outdated. Specifically, it says datastore.create() returns the object_id.
> That's wrong, it returns the actual DSObject. Furthermore, it says there are
> methods called datastore.update and datastore.get_properties, but they don't
That page documents the low level API that can be used by all
activities, no matter in which language are written. sugar.datastore
is a higher level API only available to python activities. See here
for the D-Bus API of the datastore:
> ?? The deletion/destruction of datastore activities seems to be a little
> confusing. In particular, there is a datastore.delete() method and there is
> also a DSObject.destroy() method. Why doesn't datastore.delete() simply call
> the destroy() method in its code so that any files associated with the
> deleted datastore object are also removed. Given that a warning is thrown
> telling the developer that an object is deleted without directly calling
> DSObject.destroy() (it is called indirectly through the __del__ method, but
> why not have things more explicit?), I'm not sure why this isn't just done
> programmatically. Is there ever a reason why one woul perform a delete() on
> an object without doing the functionality in DSObject.destroy() and are any
> of these reasons compelling enough that we should keep the delete() and
> destroy() methods as they are now?
Well, datastore.delete() instructs the datastore to delete the object
from its persistent storage. DSObject.destroy() is intended to be
called when the user stops needing the transient instance that
represents the persistent object.
This is similar to DB programming with SQL in procedural languages,
deleting the resultset object is not the same as deleting the rows
that are contained in that resultset.
> Other questions may come up as people work more on this documentation. In
> the meantime, I'd greatly appreciate any feedback on the existing work and
> also any answers to the questions above.
Nice work, more questions welcome.
More information about the Devel