[Sugar-devel] Journal Implementation

2010-06-10 Thread Quoc-Bao Vuong
Hello, my name is Bao Vuong. I am trying to implement a feature to the irc
that lets a journal entry store the nickname and channels. I read that I
need to define read_file and write_file methods. Are there any simple
examples I can use? Or a tutorial of how to make one to work?

Thank you.
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation

2010-06-10 Thread Michael Stone
> Hello, my name is Bao Vuong. I am trying to implement a feature to the irc
> that lets a journal entry store the nickname and channels. I read that I
> need to define read_file and write_file methods. Are there any simple
> examples I can use? Or a tutorial of how to make one to work?

Dear Pippy folks,

I think your assistance has just been requested! :)

Regards,

Michael
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation

2010-06-10 Thread Anish Mangal
Hi,

A nicely commented example (courtesy Dinko Galetic) demonstrating file
operations such as reading and writing can be found here [1].

You may also find this documentation [2] on the python website useful.

--
Cheers,
Anish

[1] 
http://git.sugarlabs.org/projects/pippy/repos/dgaletic-gsoc2010/blobs/master/data/GSOC%20examples/file%20writing%20and%20reading

[2] http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files




On Thu, Jun 10, 2010 at 8:27 PM, Michael Stone  wrote:
>> Hello, my name is Bao Vuong. I am trying to implement a feature to the irc
>> that lets a journal entry store the nickname and channels. I read that I
>> need to define read_file and write_file methods. Are there any simple
>> examples I can use? Or a tutorial of how to make one to work?
>
> Dear Pippy folks,
>
> I think your assistance has just been requested! :)
>
> Regards,
>
> Michael
>
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation

2010-06-10 Thread Martin Abente
Take a look at this hello world activity, hopefully is what you need
http://oficina.paraguayeduca.org/~mabente/codesnacks/sugar/HelloWorldDS.activity.tar.bz2

On Thu, 2010-06-10 at 10:38 -0400, Quoc-Bao Vuong wrote:
> Hello, my name is Bao Vuong. I am trying to implement a feature to the
> irc that lets a journal entry store the nickname and channels. I read
> that I need to define read_file and write_file methods. Are there any
> simple examples I can use? Or a tutorial of how to make one to work?
> 
> Thank you.
> ___
> Sugar-devel mailing list
> Sugar-devel@lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel

___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation

2010-06-10 Thread James Simmons
Bao,

Have I got a manual for you!

http://en.flossmanuals.net/ActivitiesGuideSugar/Introduction

James Simmons


> Date: Thu, 10 Jun 2010 10:38:45 -0400
> From: Quoc-Bao Vuong 
> Subject: [Sugar-devel] Journal Implementation
> To: sugar-devel@lists.sugarlabs.org
> Message-ID:
>        
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello, my name is Bao Vuong. I am trying to implement a feature to the irc
> that lets a journal entry store the nickname and channels. I read that I
> need to define read_file and write_file methods. Are there any simple
> examples I can use? Or a tutorial of how to make one to work?
>
> Thank you.
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


[Sugar-devel] Journal Implementation Help

2010-06-15 Thread Quoc-Bao Vuong
I'm a student from Arlington and am spending full-time this week and next
working on the IRC Activity. I'm trying to implement this feature:
http://bugs.sugarlabs.org/ticket/581 - which is to have the IRC Activity
recover some information from the Journal when a saved instance is resumed
(namely, the server, nickname, channels, and scrollback history - so you're
back in the place you last left your conversation).

I'm stuck, and haven't been able to find what to do next from either
googling around the wiki or asking on IRC, or blogging about it (
https://sites.google.com/a/lv5.org/bvworks/home/working-with-sugarlabs/journalimplementationtoxoirc).
Here's what I've done so far (also summarized on the ticket) and the
questions I think I need answered - any help would be appreciated.

To get started, I looked up on how the journal interacts with a Sugar
Activity, which is through the write_file() and read_file() methods. The
write_file() method of the activity will save the data given from it and
will be used later from the journal using the read_file() method. Nicknames
are stored in Network.nicks in irc.py. Channels are stored in Core.channels
in core.py. The server is stored in Network.server in irc.py. I haven't
found out where all the messages go at the moment.

When making the write_file(), I was able to read in the current nickname,
server, and channels. When I try putting them back in when opening the
latest journal, I just get the default settings. Default nickname, default
server, and default channels. The server makes sense, because
irc.freenode.net was written in the code when opening up. The channels and
nicknames were also written in the code as well, but I thought running
add_channel() or run_command("/nick myname") would overwrite those settings.
For channels, when I ran the command "/join," it did not actually add the
channel into the the Core.channels list. It only works if  I put the line
"add_channel(#example)" into the code.

so now I have some questions hoping to be answered:

* How can I overwrite the settings wanted?
* Where can I find the text for the history scrollback?
* Do the commands /nick and /join actually store the information to
their respected lists
* What is the proper way to write the write_file() and read_file()
methods for a sugar activity. I've seen two ways (using metadata and
writing/reading into files), but I'm not sure what works best for this type
of situation.

Any help would be appreciated. I'm nhacbv in #sugar and am usually online
during the US workday.


--- Bao Vuong
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation Help

2010-06-15 Thread Benjamin M. Schwartz
On 06/15/2010 12:37 PM, Quoc-Bao Vuong wrote:
> * What is the proper way to write the write_file() and read_file()
> methods for a sugar activity. I've seen two ways (using metadata and
> writing/reading into files), but I'm not sure what works best for this
> type of situation.

Either way is acceptable.  I would say "do what is easiest".  In your
case, since you are just storing a handful of string values, I would use
the metadata system.

As for your other questions, I recommend using the debug logging system to
ensure that read_file() is being called and is setting variables to their
correct stored values.  If that is working, then the problem is elsewhere
in your code (and hence is specific to the IRC activity).

--Ben



signature.asc
Description: OpenPGP digital signature
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation Help

2010-06-15 Thread Walter Bender
On Tue, Jun 15, 2010 at 12:37 PM, Quoc-Bao Vuong  wrote:
> I'm a student from Arlington and am spending full-time this week and next
> working on the IRC Activity. I'm trying to implement this feature:
> http://bugs.sugarlabs.org/ticket/581 - which is to have the IRC Activity
> recover some information from the Journal when a saved instance is resumed
> (namely, the server, nickname, channels, and scrollback history - so you're
> back in the place you last left your conversation).
> I'm stuck, and haven't been able to find what to do next from either
> googling around the wiki or asking on IRC, or blogging about it
> (https://sites.google.com/a/lv5.org/bvworks/home/working-with-sugarlabs/journalimplementationtoxoirc).
> Here's what I've done so far (also summarized on the ticket) and the
> questions I think I need answered - any help would be appreciated.
> To get started, I looked up on how the journal interacts with a Sugar
> Activity, which is through the write_file() and read_file() methods. The
> write_file() method of the activity will save the data given from it and
> will be used later from the journal using the read_file() method. Nicknames
> are stored in Network.nicks in irc.py. Channels are stored in Core.channels
> in core.py. The server is stored in Network.server in irc.py. I haven't
> found out where all the messages go at the moment.
> When making the write_file(), I was able to read in the current nickname,
> server, and channels. When I try putting them back in when opening the
> latest journal, I just get the default settings. Default nickname, default
> server, and default channels. The server makes sense, because
> irc.freenode.net was written in the code when opening up. The channels and
> nicknames were also written in the code as well, but I thought running
> add_channel() or run_command("/nick myname") would overwrite those settings.
> For channels, when I ran the command "/join," it did not actually add the
> channel into the the Core.channels list. It only works if  I put the line
> "add_channel(#example)" into the code.
> so now I have some questions hoping to be answered:
>     * How can I overwrite the settings wanted?
>     * Where can I find the text for the history scrollback?
>     * Do the commands /nick and /join actually store the information to
> their respected lists
>     * What is the proper way to write the write_file() and read_file()
> methods for a sugar activity. I've seen two ways (using metadata and
> writing/reading into files), but I'm not sure what works best for this type
> of situation.
> Any help would be appreciated. I'm nhacbv in #sugar and am usually online
> during the US workday.
>
> --- Bao Vuong
>
> ___
> Sugar-devel mailing list
> Sugar-devel@lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
>
>
Ben was too quick.

read_file and write_file are for data retrieval/storage, but simple
paramters such as nick, color, channel, etc. could just as easily be
stored in metadata. Try:

self.metadata['your key'] == value

value = self.metadata['your key']

See the abacus activity as an example.

-walter



-- 
Walter Bender
Sugar Labs
http://www.sugarlabs.org
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation Help

2010-06-15 Thread James Simmons
Bao,

Metadata *should* work just as well as saving the properties to the
Journal entry.  In practice it's a bit more complicated.  In Sugar .82
and below custom metadata does not persist across reboots.  This is
fixed now, but if you have any ambition to support .82 you need to
consider that.  .82 is the most widely used version on XO's in the
field.

Second, while writing metadata without writing out a file *should*
work in some versions of Sugar (.82, I think, maybe others) it causes
a "Keep" error.  So it if you aren't using the file part of the
Journal entry for anything else if might be a better place to store
your properties to work around these bugs in older versions of Sugar
that are still widely used.

Note that standard metadata, like Title, does persists across reboots
in all versions of Sugar.  I used this fact to work around the custom
metadata bug in .82 in my Read Etexts Activity.  I store the last page
number read at the tail end of the title.

James Simmons


> Date: Tue, 15 Jun 2010 12:37:32 -0400
> From: Quoc-Bao Vuong 
> Subject: [Sugar-devel] Journal Implementation Help
> To: sugar-devel@lists.sugarlabs.org
> Message-ID:
>        
> Content-Type: text/plain; charset="iso-8859-1"
>
>    * What is the proper way to write the write_file() and read_file()
> methods for a sugar activity. I've seen two ways (using metadata and
> writing/reading into files), but I'm not sure what works best for this type
> of situation.
>
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel


Re: [Sugar-devel] Journal Implementation Help

2010-06-15 Thread James Cameron
On Tue, Jun 15, 2010 at 12:37:32PM -0400, Quoc-Bao Vuong wrote:
> When making the write_file(), I was able to read in the current
> nickname, server, and channels. When I try putting them back in when
> opening the latest journal, I just get the default settings. Default
> nickname, default server, and default channels. The server makes
> sense, because irc.freenode.net was written in the code when opening
> up. The channels and nicknames were also written in the code as well,
> but I thought running add_channel() or run_command("/nick myname")
> would overwrite those settings. For channels, when I ran the command "
> /join," it did not actually add the channel into the the Core.channels
> list. It only works if  I put the line "add_channel(#example)" into
> the code.

I've not looked at your code, or the IRC activity, but I've written IRC
clients long ago ...  and there are some commands that will be ignored
by the server if they are delivered too quickly or before the first ping
pong response.  Resuming saved configuration from journal might well
help the activity to violate these restrictions.  So add some debug
logging to your activity so that you can verify the commands are being
sent at the right time.

-- 
James Cameron
http://quozl.linux.org.au/
___
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel