Changes

Jump to navigation Jump to search
no edit summary
Line 1: Line 1:  
{{Sugar Almanac TOC}}
 
{{Sugar Almanac TOC}}
 +
 +
= High Level Functionality of the Datastore =
 +
 +
[[Image:datastore-diagram.jpg|Overview of the Datastore]]
    
= Datastore Helper Functions =  
 
= Datastore Helper Functions =  
Line 7: Line 11:     
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
     #This method creates a datastore object that will be saved for later use by this activity.  
 
     #This method creates a datastore object that will be saved for later use by this activity.  
 
     def _create_ds_object(self):
 
     def _create_ds_object(self):
Line 19: Line 25:  
         return my_dsobject
 
         return my_dsobject
 
</pre>
 
</pre>
      
=== How do I provide a query to the datastore.find() method so that I can find datastore objects with a particular property? ===
 
=== How do I provide a query to the datastore.find() method so that I can find datastore objects with a particular property? ===
Line 25: Line 30:     
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
         ds_objects, num_objects = datastore.find({'title':'file1.txt'})   
 
         ds_objects, num_objects = datastore.find({'title':'file1.txt'})   
 
         print '------------------------- QUERY RESULTS ---------------------------'
 
         print '------------------------- QUERY RESULTS ---------------------------'
Line 39: Line 46:     
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
     ### Method: _delete_dsobjects, deletes datastore objects where prop=val  
 
     ### Method: _delete_dsobjects, deletes datastore objects where prop=val  
 
     # in the metadata
 
     # in the metadata
Line 63: Line 72:     
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
         #the datastore.get_unique_values() method should return a list of values
 
         #the datastore.get_unique_values() method should return a list of values
 
         unique_val_array = datastore.get_unique_values('activity')
 
         unique_val_array = datastore.get_unique_values('activity')
Line 85: Line 96:     
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
     #### Method: _print_all_mounts, prints all the mounts available.  
 
     #### Method: _print_all_mounts, prints all the mounts available.  
 
     def _print_all_mounts(self):
 
     def _print_all_mounts(self):
Line 102: Line 115:  
Every DSObject created by datastore.create() has a metadata property. This property refers to a [[#Class: DSMetadata | DSMetadata object]], which contains the metadata for your datastore object. The code below shows how to assign metadata values by referring to the metadata property of a DSObject.  
 
Every DSObject created by datastore.create() has a metadata property. This property refers to a [[#Class: DSMetadata | DSMetadata object]], which contains the metadata for your datastore object. The code below shows how to assign metadata values by referring to the metadata property of a DSObject.  
 
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
         #my_dsobject is of type datastore.DSObject
 
         #my_dsobject is of type datastore.DSObject
 
         my_dsobject = datastore.create()
 
         my_dsobject = datastore.create()
Line 115: Line 130:     
<pre>
 
<pre>
 +
from sugar.datastore import datastore
 +
...
 
     #### Method: _write_textfile, which creates a simple text file
 
     #### Method: _write_textfile, which creates a simple text file
 
     # with filetext as the data put in the file.  
 
     # with filetext as the data put in the file.  
Line 142: Line 159:  
         return file_dsobject
 
         return file_dsobject
    +
</pre>
 +
 +
 +
=== How do I resume an activity from the datastore programmatically? ===
 +
Every DSObject instance has a resume() method that can be called to resume the activity associated with the object. The method below demonstrates:
 +
 +
<pre>
 +
    #### Method: _resume_activty, resumes an activity associated with
 +
    # the datastore object passed to this method.
 +
    def _resume_activity(self, ds_object):
 +
        print "********* Resuming " + ds_object.metadata['title']
 +
        ds_object.resume()
 
</pre>
 
</pre>
  
Anonymous user

Navigation menu