Recent Updates to Sugar Almanac

Faisal Anwar fanwar at mediamods.com
Mon Jun 16 12:42:42 EDT 2008


Hi James,

Thanks for the feedback. I had two follow up questions for you or others who
are in the know with datastore:

1. You said: 'However, if your application is like Read, Read Etexts, or
View Slides, which are always resumed from existing Journal entries, there
is no need to write a file.  You can still save metadata, even if you don't
write a file.'

I've written the following sample code:

    def write_file(self, file_path):
        logging.debug('WRITING FILE ...')
        self.metadata['current_page'] = '3'

        #f = open(file_path, 'w')
        #try:
        #    f.write("Hello World")
        #finally:
        #    f.close()

Now, when the part about writing to a file is commented out, I get the
following error when I run my activity in the terminal:
1213618380.556841 DEBUG root: Error saving activity object to datastore:
org.freedesktop.DBus.Python.IOError: Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/dbus/service.py", line 655, in
_message_cb
    retval = candidate_method(self, *args, **keywords)
  File
"/home/fanwar/sugar-jhbuild/sugar-jhbuild/install/lib/python2.5/site-packages/olpc/datastore/datastore.py",
line 475, in update
    completion=lambda *args: self._update_completion_cb(async_cb,
async_err_cb, content, *args))
  File
"/home/fanwar/sugar-jhbuild/sugar-jhbuild/install/lib/python2.5/site-packages/olpc/datastore/backingstore.py",
line 583, in update_async
    filelike = open(filelike, "r")
IOError: [Errno 2] No such file or directory:
dbus.String(u'/home/fanwar/.sugar/default/org.laptop.AnnotateActivity/instance/1213618380')
So I guess the question is how do you just save metadata without writing to
a file? It seems that sugar errors out when I try to do that. Do you have
some sample code I could try out?


2. What exactly is the behavior (or at least the intended behavior) of
metadata and files in the datastore? What are the rules for persisting
metadata - is it a bug that it does not persist through reboots, or is this
intended functionality? Is the metadata-file model one where you always have
a single file in the datastore that maps to a specific activity instance and
metadata is always attached to this file? Or is there some other model for
how the metadata, files and activitities interact?

I guess at a fundamental level, I am wondering how the conception of journal
activities outlined at
http://wiki.laptop.org/go/OLPC_Human_Interface_Guidelines/The_Laptop_Experience/The_Journal#The_Journaltranslates
to some technical model for how stuff is stored. My understanding
(from talking to other sugar developers and looking at what you've written
at Beyond Hello World) has been that datastore has files and metadata for
each activity- but it seems that if everything is supposed to be abstracted
as an activity, then there should be some data structure that represents
this and then the files and metadata are there to give additional
information about the activity itself. This would avoid confusion as to
whether there must be a file or metadata or some other ancillary information
to save an activity.

Faisal



On Mon, Jun 16, 2008 at 10:13 AM, James Simmons <jim.simmons at walgreens.com>
wrote:

> Faisal,
>
> What you wrote looks good, but I did see a possible error in it.  You say:
>
> "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)."
>
> I think this is not always true.  Now if you're creating a new Journal
> entry for your app and have implemented write_file it *might* be true.
>  However, if your application is like Read, Read Etexts, or View Slides,
> which are always resumed from existing Journal entries, there is no need to
> write a file.  You can still save metadata, even if you don't write a file.
>
> Another thing worth pointing out is that metadata doesn't work very well
> right now.  If I was in the position where I needed to write a file but
> didn't have anything that needed to go into it I wouldn't use metadata at
> all.  Instead I would put any saved options, etc. in the file, because
> *that* would persist across reboots but metadata currently does not.  I
> think several activities already do this.
>
> I wrote a wiki page titled "Beyond Hello World" that covers much the same
> ground as yours, but I like yours better.
>
> Thanks,
>
> James Simmons
>
>
>
> Date: Fri, 13 Jun 2008 17:34:43 -0400
> From: "Faisal Anwar" <fanwar at mediamods.com>
> Subject: Recent Updates to Sugar Almanac
> To: devel at lists.laptop.org, sugar at laptop.org
> Message-ID:
>        <1d23499d0806131434q3602061dj7401bf71a12b0c52 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
>
> Hello All,
>
> As many of you know, I'm writing up a sugar almanac to help new
> sugar/python
> developers get up and running with creating useful activities. I will try
> to
> send frequent updates in terms of what has been added. In addition to using
> the documentation, I'd appreciate it if people familiar with the different
> modules I am writing can send any better or alternative code examples to
> the
> ones that I have written. Review and feedback is ALWAYS appreciated.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.laptop.org/pipermail/devel/attachments/20080616/66588d34/attachment.html>


More information about the Devel mailing list