Hack Dan's DataStore for doing what we need for 6th March demo.
parent
921bccd48c
commit
d504124cc2
@ -0,0 +1,65 @@
|
||||
import time
|
||||
import os
|
||||
|
||||
def insert_demo_data(data_store):
|
||||
home_dir = os.path.expanduser('~')
|
||||
journal_dir = os.path.join(home_dir, "Journal")
|
||||
if not os.path.exists(journal_dir):
|
||||
os.makedirs(journal_dir, 0755)
|
||||
|
||||
data = [
|
||||
{ 'file-path' : os.path.join(journal_dir, 'fishes_in_the_sea.rtf'),
|
||||
'object-type' : 'text',
|
||||
'date' : str(time.time() - 100000),
|
||||
'title' : 'Fishes in the Sea',
|
||||
'preview' : 'There are many fishes in the sea, and not only...',
|
||||
'icon' : 'theme:object-text',
|
||||
'icon-color' : '#C2B00C,#785C78',
|
||||
'keep' : '0',
|
||||
'buddies' : str([ { 'name' : 'Marco',
|
||||
'color' : '#C2B00C,#785C78' },
|
||||
{ 'name' : 'Dan',
|
||||
'color' : '#75C228,#3A6E3A' } ])
|
||||
},
|
||||
{ 'file-path' : os.path.join(journal_dir, 'my_cat_and_my_fishes.rtf'),
|
||||
'object-type' : 'text',
|
||||
'date' : str(time.time() - 200000),
|
||||
'title' : 'My cat and my fishes',
|
||||
'preview' : "Don't know why, but my cat looks to like my fishe...",
|
||||
'icon' : 'theme:object-text',
|
||||
'icon-color' : '#C2B00C,#785C78',
|
||||
'keep' : '1',
|
||||
'buddies' : str([ { 'name' : 'Eben',
|
||||
'color' : '#C2B00C,#785C78' },
|
||||
{ 'name' : 'Dan',
|
||||
'color' : '#75C228,#3A6E3A' } ])
|
||||
},
|
||||
{ 'file-path' : os.path.join(journal_dir, 'cat_browsing.hist'),
|
||||
'object-type' : 'link',
|
||||
'date' : str(time.time() - 300000),
|
||||
'title' : 'About cats',
|
||||
'preview' : "http://en.wikipedia.org/wiki/Cat",
|
||||
'icon' : 'theme:object-link',
|
||||
'icon-color' : '#C2B00C,#785C78',
|
||||
'keep' : '0',
|
||||
'buddies' : str([ { 'name' : 'Dan',
|
||||
'color' : '#C2B00C,#785C78' },
|
||||
{ 'name' : 'Tomeu',
|
||||
'color' : '#75C228,#3A6E3A' } ])
|
||||
},
|
||||
{ 'file-path' : os.path.join(journal_dir, 'our_school.jpeg'),
|
||||
'object-type' : 'picture',
|
||||
'date' : str(time.time() - 400000),
|
||||
'title' : 'Our school',
|
||||
'preview' : "Our school",
|
||||
'icon' : 'theme:object-image',
|
||||
'icon-color' : '#C2B00C,#785C78',
|
||||
'keep' : '0',
|
||||
'buddies' : str([ { 'name' : 'Marco',
|
||||
'color' : '#C2B00C,#785C78' },
|
||||
{ 'name' : 'Eben',
|
||||
'color' : '#75C228,#3A6E3A' } ])
|
||||
}
|
||||
]
|
||||
for obj in data:
|
||||
data_store.create(obj)
|
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (C) 2006, One Laptop Per Child
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
from sugar.datastore import datastore
|
||||
from sugar.datastore.datastore import Text
|
||||
|
||||
# Write a text object
|
||||
metadata = { 'date' : 1000900000,
|
||||
'title' : 'Thai history',
|
||||
'preview' : 'The subject of thai history...',
|
||||
'icon-color' : '#C2B00C,#785C78',
|
||||
}
|
||||
text = Text(metadata)
|
||||
f = open("/tmp/hello.txt", 'w')
|
||||
try:
|
||||
f.write('The subject of thai history blah blah blah, blah blah blah and blah.')
|
||||
finally:
|
||||
f.close()
|
||||
text.set_file_path(f.name)
|
||||
handle = datastore.write(text)
|
||||
|
||||
# Read back that object
|
||||
thing = datastore.read(handle)
|
||||
metadata = thing.get_metadata()
|
||||
print metadata
|
||||
|
||||
file_path = thing.get_file_path()
|
||||
f = open(file_path)
|
||||
try:
|
||||
print f.read()
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# Retrieve all the objects
|
||||
objects = datastore.find('')
|
||||
for obj in objects:
|
||||
print obj.get_metadata()['title']
|
Loading…
Reference in New Issue