Sugar.datastore.datastore

From OLPC
Revision as of 16:48, 18 June 2008 by Fanwar (talk | contribs) (How do I create a new datastore object?)
Jump to: navigation, search

Sugar Almanac for Developers

Sugar Almanac Main Page

Package: sugar

sugar.env

sugar.profile

sugar.mime

Package: sugar.activity

sugar.activity.activity

sugar.activity.registry

Package: sugar.graphics

sugar.graphics.alert

sugar.graphics.toolbutton

sugar.graphics.toolbox

Package: sugar.datastore

sugar.datastore.datastore

Logging

sugar.logger

Notes on using Python Standard Logging in Sugar

Internationalization

Internationalization in Sugar

How do I create a new datastore object?

In addition to the write_file() method, which allows sugar's activity code to save your activity by creating a datastore object, you can explicitly create datastore objects in your activity code using the datastore.create() method. The following code shows how a new datastore object is created and then actually written to the datastore. Other sections will discuss how this datastore object can actually be assigned to files and populated with useful metadata.

    #This method creates a datastore object that will be saved for later use by this activity. 
    def _create_ds_object(self):
        #my_dsobject is of type datastore.DSObject
        my_dsobject = datastore.create()

        # ... you can put any code to change your datastore file and metadata here ...

        #Persist this newly created datastore object in the datastore for later access. 
        datastore.write(my_dsobject)

        return my_dsobject

Notes

<references />