Sugar.datastore.datastore: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
=== Briefly, what is the sugar datastore? ===
=== Briefly, what is the sugar datastore? ===

=== How do I save my activity data to the datastore? ===

Most basic activities can be frozen in the datastore by implementing the write_file() method within the main activity class. This method is then called by sugar to save the activity when it is closed or when user or program commands request that the activity be saved to the datastore. Once saved, the activity can be accessed and reloaded from the journal.

The following simple write_file() method shows how both metadata and files are written. Currently, write_file() will throw an error unless somewhere you actually write an actual file to the file_path that is passed to write_file. The code below writes a dummy file within the body of write_file itself (you can do this elsewhere as long as you have a handle on the file_path variable used by write_file).

def write_file(self, file_path):
logging.debug('WRITING FILE ...')
#save some metadata
self.metadata['current_page'] = '3'
#save the file itself
f = open(file_path, 'w')
try:
f.write("Hello World")
finally:
f.close()





Revision as of 20:45, 13 June 2008

Briefly, what is the sugar datastore?

How do I save my activity data to the datastore?

Most basic activities can be frozen in the datastore by implementing the write_file() method within the main activity class. This method is then called by sugar to save the activity when it is closed or when user or program commands request that the activity be saved to the datastore. Once saved, the activity can be accessed and reloaded from the journal.

The following simple write_file() method shows how both metadata and files are written. Currently, write_file() will throw an error unless somewhere you actually write an actual file to the file_path that is passed to write_file. The code below writes a dummy file within the body of write_file itself (you can do this elsewhere as long as you have a handle on the file_path variable used by write_file).

   def write_file(self, file_path):
       logging.debug('WRITING FILE ...')
       #save some metadata
       self.metadata['current_page'] = '3'
       #save the file itself
       f = open(file_path, 'w')
       try:
           f.write("Hello World")
       finally:
           f.close()



Notes

<references />