[squeak-dev] Files documentation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Files documentation

Mariano Martinez Peck
Hi list!

I need to do some things with files (text and binaries), and I would need information about creating, deleting, adding, appending, writting and so on with them. I look in SBE but I didn't find a chapter about that.

Is somewhere documentation about this?

thanks,

Mariano


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

David Mitchell-10
I'd recommend starting with
http://wiki.squeak.org/squeak/5929

It describes Rio, which is a library you can load.

Even if you don't use Rio, reading this will cover most of the use
cases for which you will need to use FileDirectory.

pharo is moving toward using Rio in its base image.

On Mon, Nov 24, 2008 at 12:20 PM, Mariano Martinez Peck
<[hidden email]> wrote:

> Hi list!
>
> I need to do some things with files (text and binaries), and I would need
> information about creating, deleting, adding, appending, writting and so on
> with them. I look in SBE but I didn't find a chapter about that.
>
> Is somewhere documentation about this?
>
> thanks,
>
> Mariano
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

keith1y
In reply to this post by Mariano Martinez Peck
Mariano Martinez Peck wrote:

> Hi list!
>
> I need to do some things with files (text and binaries), and I would
> need information about creating, deleting, adding, appending, writting
> and so on with them. I look in SBE but I didn't find a chapter about that.
>
> Is somewhere documentation about this?
>
> thanks,
>
> Mariano
The built in File handling is not very elegent, enter, "Rio" File/Drectory

Installer squeaksource project: 'Rio'; install: 'File-Kernel'; install:
'File-Base'.

(and File-Tests for examples)

see also http://wiki.squeak.org/squeak/5929

if you like it, then perhaps you would be kind enough to offer some feedback

best regards

Keith

=========
Class comment from File reads:

Features of File/Directory (née Rio)

File/Directory was inspired by ruby's rio which enables local and remote
files to be used transparently. To achieve this a generic stream copy
function has been developed (aStream copyTo: bStream) and we are able to
expose the working stream of FtpClient so you can stream directly to a
remote file. We also support file archives (zip) as if they were a
filesystem, and transparent streaming to compressed files (gzip).
[transparent streaming to a remote compressed file is still available as
a exercise for the reader to implement ;) ]

File/Directory is a standalone package, it does not use any of the
existing FileDirectory classes. It is separated into File-Kernel and
File-Base, where the former provides a minimal working subset for
KernelImages to access local filesystems.

Local file copying is handled by the fileCopyPlugin if it is present, if
not OSProcess 'cp' is used, and as a last resort a full stream to stream
copyTo: is performed (but this does update modification time).

Remote file upload or download is handled by OSProcess 'ftp' if it is
present. Multiple file transfers are invoked N at a time (where N is
initially 5). Copying from a remote file to another remote file is
handled by the internal stream copy function.


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

Mariano Martinez Peck
David and Keith: Thanks you for your reply.

I will see and try to use RIO. However, what I need to do is very simple. I have already add log to SqueakDBX. Till now, the log just print in Transcript. The problem is that sometimes I get a segmentation fault and I cannot see transcript any more haha. So, I would like to be able to log into a log file.

If I think I could give some useful feedback be sure I will let you know.

cheers,

Mariano


On Mon, Nov 24, 2008 at 4:53 PM, Keith Hodges <[hidden email]> wrote:
Mariano Martinez Peck wrote:
> Hi list!
>
> I need to do some things with files (text and binaries), and I would
> need information about creating, deleting, adding, appending, writting
> and so on with them. I look in SBE but I didn't find a chapter about that.
>
> Is somewhere documentation about this?
>
> thanks,
>
> Mariano
The built in File handling is not very elegent, enter, "Rio" File/Drectory

Installer squeaksource project: 'Rio'; install: 'File-Kernel'; install:
'File-Base'.

(and File-Tests for examples)

see also http://wiki.squeak.org/squeak/5929

if you like it, then perhaps you would be kind enough to offer some feedback

best regards

Keith

=========
Class comment from File reads:

Features of File/Directory (née Rio)

File/Directory was inspired by ruby's rio which enables local and remote
files to be used transparently. To achieve this a generic stream copy
function has been developed (aStream copyTo: bStream) and we are able to
expose the working stream of FtpClient so you can stream directly to a
remote file. We also support file archives (zip) as if they were a
filesystem, and transparent streaming to compressed files (gzip).
[transparent streaming to a remote compressed file is still available as
a exercise for the reader to implement ;) ]

File/Directory is a standalone package, it does not use any of the
existing FileDirectory classes. It is separated into File-Kernel and
File-Base, where the former provides a minimal working subset for
KernelImages to access local filesystems.

Local file copying is handled by the fileCopyPlugin if it is present, if
not OSProcess 'cp' is used, and as a last resort a full stream to stream
copyTo: is performed (but this does update modification time).

Remote file upload or download is handled by OSProcess 'ftp' if it is
present. Multiple file transfers are invoked N at a time (where N is
initially 5). Copying from a remote file to another remote file is
handled by the internal stream copy function.





Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

keith1y
Mariano Martinez Peck wrote:

> David and Keith: Thanks you for your reply.
>
> I will see and try to use RIO. However, what I need to do is very
> simple. I have already add log to SqueakDBX. Till now, the log just
> print in Transcript. The problem is that sometimes I get a
> segmentation fault and I cannot see transcript any more haha. So, I
> would like to be able to log into a log file.
>
> If I think I could give some useful feedback be sure I will let you know.
>
> cheers,
>
> Mariano

Ah! Logging! Why didnt you say so.

We would like to move Squeak to use some form of proper logging
interface, rather than blindly throwing stuff at transcript show. (which
is not thread safe)

The current proposal is "Logging". (Installer install: 'Logging') This
provides a front end to the users choice of available logging
frameworks. Toothpick, and SimpleLog are currently supported.

Documentation: http://installer.pbwiki.com/Logging

regards

Keith

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

Mariano Martinez Peck
Keith: hahahah. I know there was a "Logging" project, but as there were few places where to log, I decided to do it by hand. Do you think it should be better to do it with it altought I have few places to log ?

Just by curious, is Logging something like log4j (sorry, but that's what I know :( ?

does Logging use RIO for files ?

thanks,

Mariano

On Mon, Nov 24, 2008 at 6:05 PM, Keith Hodges <[hidden email]> wrote:
Mariano Martinez Peck wrote:
> David and Keith: Thanks you for your reply.
>
> I will see and try to use RIO. However, what I need to do is very
> simple. I have already add log to SqueakDBX. Till now, the log just
> print in Transcript. The problem is that sometimes I get a
> segmentation fault and I cannot see transcript any more haha. So, I
> would like to be able to log into a log file.
>
> If I think I could give some useful feedback be sure I will let you know.
>
> cheers,
>
> Mariano

Ah! Logging! Why didnt you say so.

We would like to move Squeak to use some form of proper logging
interface, rather than blindly throwing stuff at transcript show. (which
is not thread safe)

The current proposal is "Logging". (Installer install: 'Logging') This
provides a front end to the users choice of available logging
frameworks. Toothpick, and SimpleLog are currently supported.

Documentation: http://installer.pbwiki.com/Logging

regards

Keith




Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

keith1y
Mariano Martinez Peck wrote:
> Keith: hahahah. I know there was a "Logging" project, but as there
> were few places where to log, I decided to do it by hand. Do you think
> it should be better to do it with it altought I have few places to log ?
>
Definitely.

That is exactly what Logging is there for, so that people are encouraged
to put the log code in their packages without worrying about how the
actual logging is done, timestamped etc. You can let the user choose how
the output is provided/used/managed (e.g. SimpleLog does log file
rotation). The default backend is simply a Null instance (it
should/could be a minimal Transcript Log equivalent to Transcript show:)

There are also utilities for timing events, so you could start a timer
when you send a query and print it when you get the result.
> Just by curious, is Logging something like log4j (sorry, but that's
> what I know :( ?
>
> does Logging use RIO for files ?
>
> thanks,
>
> Mariano
If you load "SimpleLog" (from the gjallar team) this uses Syslog,
transcript, LogMorph or files (not rio, just a basic filestream)

Keith

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Files documentation

Mariano Martinez Peck
ok. If you say so, I will try it as soon as I have time and I will let you know my feedback and any question I have with it.

thanks!

mariano

On Mon, Nov 24, 2008 at 6:42 PM, Keith Hodges <[hidden email]> wrote:
Mariano Martinez Peck wrote:
> Keith: hahahah. I know there was a "Logging" project, but as there
> were few places where to log, I decided to do it by hand. Do you think
> it should be better to do it with it altought I have few places to log ?
>
Definitely.

That is exactly what Logging is there for, so that people are encouraged
to put the log code in their packages without worrying about how the
actual logging is done, timestamped etc. You can let the user choose how
the output is provided/used/managed (e.g. SimpleLog does log file
rotation). The default backend is simply a Null instance (it
should/could be a minimal Transcript Log equivalent to Transcript show:)

There are also utilities for timing events, so you could start a timer
when you send a query and print it when you get the result.
> Just by curious, is Logging something like log4j (sorry, but that's
> what I know :( ?
>
> does Logging use RIO for files ?
>
> thanks,
>
> Mariano
If you load "SimpleLog" (from the gjallar team) this uses Syslog,
transcript, LogMorph or files (not rio, just a basic filestream)

Keith




Reply | Threaded
Open this post in threaded view
|

How to do logging (was Re: [squeak-dev] Files documentation)

Göran Krampe
Hi!

Mariano Martinez Peck wrote:
> ok. If you say so, I will try it as soon as I have time and I will let
> you know my feedback and any question I have with it.

I recommend (of course) using "SimpleLog", and optionally with the
"Logging" frontend from Keith.

SimpleLog was developed in the Gjallar project and it has the following
goodness:

- Simple. :)
- Uses the standard syslog levels.
- Has a UDP based syslog backend. Fast and very useful.
- Has a Morphic viewer which is quite nice and has filtering abilities.
- Has log file rotation.
- Can still log to Transcript but it is protected by a mutex.

If you need to use external monitoring/alarm tools and/or suddenly need
to deploy an app "clustered" then the syslog backend is very nice to
have. Otherwise you end up with one log file per "clustered image" which
is not so nice.

If you use the "Logging" frontend (which I haven't used myself) then you
of course have options to choose backends.

regards, Göran


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: Files documentation

Sophie424
In reply to this post by keith1y
"Keith Hodges" <[hidden email]> wrote in message

> The built in File handling is not very elegent, enter, "Rio" File/Drectory
>
> Installer squeaksource project: 'Rio'; install: 'File-Kernel'; install:
> 'File-Base'.

On Damien's 3.10 dev image I get warnings about FileLocalExecutive, which
appears undefined both at start and end of the install.

- Sophie




Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

Mariano Martinez Peck
In reply to this post by Göran Krampe
Göran: Yesterday night we have a very good discussion about logging in IRC. I was asking about Logging in order to add log to SqueakDBX. I think there were some interesting questions:

1) Should a framework, like SqueakDBX, log? Or this is a responsibility of the "user" of the framework ?

Here, I will say: I think framework must log because it helps the framework team to find out bugs or give them information about it. I think this is something good. Obviously the framework should only log things related to the framework itself and not logic related with the user of it.

2) If so, should it be optional ?
I think i must.  I mean, user can enable or disable it.

3) Suppose I want very much performance, and the user disable logging. Which is the best way of doing this?

4) No matter 1) to 3), framework's user can log. I mean, it can do something like [xxxx] on: DBXError do:[ self log 'something' ]

In fact, I decided (actually I must discuss with the team) to use Logging and SimpleLog in SqueakDBX.

Any opinion about this?
 

On Tue, Nov 25, 2008 at 8:21 AM, Göran Krampe <[hidden email]> wrote:
Hi!

Mariano Martinez Peck wrote:
ok. If you say so, I will try it as soon as I have time and I will let you know my feedback and any question I have with it.

I recommend (of course) using "SimpleLog", and optionally with the
"Logging" frontend from Keith.

SimpleLog was developed in the Gjallar project and it has the following
goodness:

- Simple. :)
- Uses the standard syslog levels.
- Has a UDP based syslog backend. Fast and very useful.
- Has a Morphic viewer which is quite nice and has filtering abilities.
- Has log file rotation.
- Can still log to Transcript but it is protected by a mutex.

If you need to use external monitoring/alarm tools and/or suddenly need
to deploy an app "clustered" then the syslog backend is very nice to
have. Otherwise you end up with one log file per "clustered image" which
is not so nice.

If you use the "Logging" frontend (which I haven't used myself) then you
of course have options to choose backends.

regards, Göran





Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: Files documentation

keith1y
In reply to this post by Sophie424
Sophie (itsme213) wrote:

> "Keith Hodges" <[hidden email]> wrote in message
>
>  
>> The built in File handling is not very elegent, enter, "Rio" File/Drectory
>>
>> Installer squeaksource project: 'Rio'; install: 'File-Kernel'; install:
>> 'File-Base'.
>>    
>
> On Damien's 3.10 dev image I get warnings about FileLocalExecutive, which
> appears undefined both at start and end of the install.
>
> - Sophie
>  
Hello, sorry my mistake, I moved FileExecutive from Kile-Kernel to
File-Base just for coding convenience  (i.e. temporarily) and forgot to
move it back at 5am. (MC1.5 wouldnt have minded since it supports out of
order loading)

hopefully all is well now, and all (152) tests are passing

Keith

Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

keith1y
In reply to this post by Mariano Martinez Peck
Mariano Martinez Peck wrote:

> Göran: Yesterday night we have a very good discussion about logging in
> IRC. I was asking about Logging in order to add log to SqueakDBX. I
> think there were some interesting questions:
>
> 1) Should a framework, like SqueakDBX, log? Or this is a
> responsibility of the "user" of the framework ?
>
> Here, I will say: I think framework must log because it helps the
> framework team to find out bugs or give them information about it. I
> think this is something good. Obviously the framework should only log
> things related to the framework itself and not logic related with the
> user of it.
>
> 2) If so, should it be optional ?
> I think i must.  I mean, user can enable or disable it.
In Logging, not only does the user get to enable to backend of their
choice, but the user gets to choose a LogRouter.

If you subclass LogRouter you have complete control over what is and is
not logged. So different Logging policies can easily be defined.

What is required is some standardisation so that a consistent experience
is found accross multiple frameworks.
> 3) Suppose I want very much performance, and the user disable logging.
> Which is the best way of doing this?
The other way that I use, and it is talked about in the "Smalltalk
superpowers videos", is having the users client class in a framework
such that the logging version is a subclass. Thus the user can choose
whether or not to run your framework with logging enabled or not.

We do this in magma by setting choosing a ReadStrategy that logs stuff.
>
> 4) No matter 1) to 3), framework's user can log. I mean, it can do
> something like [xxxx] on: DBXError do:[ self log 'something' ]
>
> In fact, I decided (actually I must discuss with the team) to use
> Logging and SimpleLog in SqueakDBX.
>
> Any opinion about this?
>  
 Great news, I look forward to using SqueakDBX in the future

Keith

Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

Göran Krampe
In reply to this post by Mariano Martinez Peck
Hi again!

Mariano Martinez Peck wrote:
> Göran: Yesterday night we have a very good discussion about logging in
> IRC. I was asking about Logging in order to add log to SqueakDBX. I
> think there were some interesting questions:
>
> 1) Should a framework, like SqueakDBX, log? Or this is a responsibility
> of the "user" of the framework ?

I think it definitely should log. :)

> Here, I will say: I think framework must log because it helps the
> framework team to find out bugs or give them information about it. I
> think this is something good. Obviously the framework should only log
> things related to the framework itself and not logic related with the
> user of it.

Right.

> 2) If so, should it be optional ?
> I think i must.  I mean, user can enable or disable it.

Yep.

> 3) Suppose I want very much performance, and the user disable logging.
> Which is the best way of doing this?

Good question. :) As Keith noted you can do tricks with subclasses etc.
I haven't bothered looking into disabling logging "the fastest way" much
for SimpleLog, and now since Keith has taken the "front seat" :) perhaps
that is now an issue more suitable to deal with in his "Logging" package.

> 4) No matter 1) to 3), framework's user can log. I mean, it can do
> something like [xxxx] on: DBXError do:[ self log 'something' ]

Right.

> In fact, I decided (actually I must discuss with the team) to use
> Logging and SimpleLog in SqueakDBX.
>
> Any opinion about this?

Just happy to hear it! :)

regards, Göran


Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

keith1y
Hello All,

I need a villainous superpower that I haven't needed before, can anyone
tell me how to achieve this.

I have some code like this:

self send a message to me.
self nextThing.

or

self send a message to me.
A := self nextThing.

What naughty superpower code can I put in to #send that will jump
execution to self nextThing directly?

many thanks in advance

Keith

Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

Avi Bryant-2
On Thu, Nov 27, 2008 at 9:44 AM, Keith Hodges <[hidden email]> wrote:

> self send a message to me.
> A := self nextThing.
>
> What naughty superpower code can I put in to #send that will jump
> execution to self nextThing directly?

Have #send return an object which has #doesNotUnderstand: implemented as ^ self.

This is a "message eating nil" - see also:

http://web.archive.org/web/20060223010948/http://www.smalltalkpro.com/general.html

Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

Damien Cassou-3
On Thu, Nov 27, 2008 at 6:52 PM, Avi Bryant <[hidden email]> wrote:
>> What naughty superpower code can I put in to #send that will jump
>> execution to self nextThing directly?
>
> Have #send return an object which has #doesNotUnderstand: implemented as ^ self.
>
> This is a "message eating nil" - see also:
>
> http://web.archive.org/web/20060223010948/http://www.smalltalkpro.com/general.html

http://wiki.squeak.org/squeak/5962

--
Damien Cassou
http://damiencassou.seasidehosting.st

Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

keith1y
In reply to this post by Avi Bryant-2
Avi Bryant wrote:

> On Thu, Nov 27, 2008 at 9:44 AM, Keith Hodges <[hidden email]> wrote:
>
>  
>> self send a message to me.
>> A := self nextThing.
>>
>> What naughty superpower code can I put in to #send that will jump
>> execution to self nextThing directly?
>>    
>
> Have #send return an object which has #doesNotUnderstand: implemented as ^ self.
>
> This is a "message eating nil" - see also:
>  
Thanks Avi,

Indeed, I am a champion of the message eating null, see
http://www.squeaksource.com/Null for squeak.

That's what I am doing already. The problem is that the arguments to
these methods may take a long time to calculate so I am looking for a
short cut, all beit an evil one.

regards

Keith

Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

Bert Freudenberg
In reply to this post by keith1y

On 27.11.2008, at 18:44, Keith Hodges wrote:

> Hello All,
>
> I need a villainous superpower that I haven't needed before, can  
> anyone
> tell me how to achieve this.
>
> I have some code like this:
>
> self send a message to me.
> self nextThing.
>
> or
>
> self send a message to me.
> A := self nextThing.
>
> What naughty superpower code can I put in to #send that will jump
> execution to self nextThing directly?


send
        ...
        thisContext sender jump: 4

This skips 4 bytecodes in the calling method before returning, so  
instead of pc=31 it continues at pc=35:

29 <70> self
30 <D4> send: send
31 <D3> send: a
32 <D2> send: message
33 <D1> send: to
34 <D0> send: me
35 <87> pop
36 <70> self
37 <D5> send: nextThing
38 <87> pop
39 <78> returnSelf

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: How to do logging (was Re: [squeak-dev] Files documentation)

Michael van der Gulik-2
In reply to this post by keith1y


On Fri, Nov 28, 2008 at 6:44 AM, Keith Hodges <[hidden email]> wrote:
Hello All,

I need a villainous superpower that I haven't needed before, can anyone
tell me how to achieve this.

I have some code like this:

self send a message to me.
self nextThing.

or

self send a message to me.
A := self nextThing.

What naughty superpower code can I put in to #send that will jump
execution to self nextThing directly?


In terms of code smells, this competes pretty well with fresh sewerage! Surely there's a better solution at a higher level in your code?

Gulik.

--
http://people.squeakfoundation.org/person/mikevdg
http://gulik.pbwiki.com/


12