Changes
Jump to navigation
Jump to search
Line 1:
Line 1:
+
+
+
+
Line 7:
Line 11:
+
+
Line 19:
Line 25:
−
Line 25:
Line 30:
+
+
Line 39:
Line 46:
+
+
Line 63:
Line 72:
+
+
Line 85:
Line 96:
+
+
Line 102:
Line 115:
+
+
Line 115:
Line 130:
+
+
Line 142:
Line 159:
+
+
+
+
+
+
+
+
+
+
+
+
Development Team/Almanac/sugar.datastore.datastore (view source)
Revision as of 13:43, 24 June 2008
, 13:43, 24 June 2008no edit summary
{{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 =
<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):
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? ===
<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 ---------------------------'
<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
<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')
<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):
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()
<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.
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>