Squeak scripts in UNIX

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

Re: Squeak scripts in UNIX

NorbertHartl
On Wed, 2007-02-14 at 15:12 -0500, Lex Spoon wrote:

> Bert Freudenberg <[hidden email]> writes:
> > The harder part is that there is no concept of a current working
> > directory in Squeak. To find the script, you need to convert a
> > relative path to the absolute one using cwd. This can either be done
> > in the shell script, or one could abuse the SecurityPlugin which
> > listens to environment variables ... or extend the VM ... or use
> > OSProcess ...
>
> On Unix, "FileDirectory default" gives you the Unix cwd.  And at any
> rate, this is the "default" directory, so it is at least a defensible
> place to start if you are given a relative path.
>
>
> That said, that's very interesting that using the absolute path works
> already.  Maybe the easiest thing, then, is to come up with some
> shell-script magic to rewrite $0 into an absolute path.  Do any Unix
> hackers here know how to do that?
>
$PWD/$0

always resemble an absolute path.

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Bert Freudenberg

On Feb 15, 2007, at 10:40 , Norbert Hartl wrote:

> On Wed, 2007-02-14 at 15:12 -0500, Lex Spoon wrote:
>> Maybe the easiest thing, then, is to come up with some
>> shell-script magic to rewrite $0 into an absolute path.  Do any Unix
>> hackers here know how to do that?
>>
> $PWD/$0
>
> always resemble an absolute path.

But the wrong one in case $0 is already absolute.

In C you have realpath(), but in the shell I think you must test for  
the path being absolute or not.

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

NorbertHartl
On Thu, 2007-02-15 at 11:39 +0100, Bert Freudenberg wrote:

> On Feb 15, 2007, at 10:40 , Norbert Hartl wrote:
>
> > On Wed, 2007-02-14 at 15:12 -0500, Lex Spoon wrote:
> >> Maybe the easiest thing, then, is to come up with some
> >> shell-script magic to rewrite $0 into an absolute path.  Do any Unix
> >> hackers here know how to do that?
> >>
> > $PWD/$0
> >
> > always resemble an absolute path.
>
> But the wrong one in case $0 is already absolute.
>
> In C you have realpath(), but in the shell I think you must test for  
> the path being absolute or not.
>
Yes, you are right. I was again too quick and too lazy
at the same time ;)

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

keith1y
In reply to this post by keith1y
Addendum, FYI the output of

squeak -- Script +help

from the command line 'Launcher' enabled image (see previous email)
gives the following overview of the resources available from the command
line.

cheers

Keith

---
Installer

path=/dir/*.txt          Specify a search path for the item to install
p=/dir1/*.txt;<url2>/    Multiple items delimited by ;
                         The page name is typically appended to the path
string, or
                         if a "*" is present, it will be replaced by the
page name.

in,i,install=<page>      Page appended to the path to begin the install
process
url,u=<url>              Install using an explicit url from which to
obtain a script or file
+debug                   Do not trap errors
view=<page>              Print the script that would have been installed.

For more options use Script eval="Installer ... "


Launcher

scripts="<sc.st> <sc2.st>"   Execute smalltalk scripts given by urls.

MCWorkingCopy

report=workingCopies     Print a list of the current Monticello packages
                         and their versions
to="*.txt"               Filename or pattern to write report to (default
is stdout)


Script

+help,h                  Prints this help text.
eval, e="2+2"            Evaluate code and quit.
print, p="2+2"           Evaluate and print result to stdout and quit.
-quit                    Remain open after evaluating code

SmalltalkImage

+save                    Save image
save=name.image          Save image with given file name
+quit                    Quit squeak


SystemNavigation

report=method            Execute the query method and print the results
to stdout or file.
to="*.txt"               Filename or pattern to write report to (default
is stdout).


TestRunner

+default                 Include default suites, (this is the default)
                         #(#allStandardTests #toDo #expectedFailures)
-default                 Exclude default suites.
suites=#one#two          List of suites delimited by #
+filter                  Filters will select from the suites
-filter                  Filters will exclude from the suites (the default)
categories=Cat1;Cat2     List of categories delimited by ;
classes=Class;Class2     List of classes delimited by ;


WAKom

+stop                    Stops the WAKom server
start=<p>                Starts the server on the given port




               
___________________________________________________________
The all-new Yahoo! Mail goes wherever you go - free your email address from your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html

Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Bert Freudenberg

On Feb 16, 2007, at 11:21 , Keith Hodges wrote:

> Addendum, FYI the output of
>
> squeak -- Script +help
>
> from the command line 'Launcher' enabled image (see previous email)
> gives the following overview of the resources available from the  
> command line.

What's the reasoning behind this? Why not simply allow Smalltalk code  
to be passed on the command line?

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Lex Spoon-3
In reply to this post by David T. Lewis
"David T. Lewis" <[hidden email]> writes:
> > >On Unix, "FileDirectory default" gives you the Unix cwd.
> >
> > No. It gives you the image directory.
>
> There is a "current working directory" introduced into CommandShell,
> but as Bert says is a concept that does not exist in Squeak, so it
> had to be added. Furthermore, it works on a per-volume basis in Windows
> (C: drive versus D: drive, etc), so it's not clear that this is a
> very portable concept.

I see.  In the example script header I posted, they would be the same
directory, but if you reuse an image in a stock location then they
would be different.

Why is the default directory set to the image's directory, anyway?
That seems like zero bits of information: you can already compute it
from the image's filename.  Additionally, isn't the most sensible
"default directory" the same as the "default directory" (cwd) of the
calling process?


-Lex


Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Lex Spoon-3
In reply to this post by Bert Freudenberg
Bert Freudenberg <[hidden email]> writes:

> On Feb 16, 2007, at 11:21 , Keith Hodges wrote:
>
> > Addendum, FYI the output of
> >
> > squeak -- Script +help
> >
> > from the command line 'Launcher' enabled image (see previous email)
> > gives the following overview of the resources available from the
> > command line.
>
> What's the reasoning behind this? Why not simply allow Smalltalk code
> to be passed on the command line?

Good question.  That seems simpler, easier to learn, and more
powerful.

Overall, though, this is very slick, Keith!  I hope it can get
cleaned up to something that looks good to everyone, and then
folded into 3.10.


-Lex



Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

timrowledge
In reply to this post by Lex Spoon-3

On 16-Feb-07, at 8:20 AM, Lex Spoon wrote:


>
> Why is the default directory set to the image's directory, anyway?
> That seems like zero bits of information: you can already compute it
> from the image's filename.  Additionally, isn't the most sensible
> "default directory" the same as the "default directory" (cwd) of the
> calling process?

In the general case, because it is the only directory you can be sure  
of across platforms. Not all systems have any concept of a 'current  
working directory'. And of course, the default directory name *is*  
worked out from the image name.

A faintly plausible alternative would be if the image were allowed to  
be in a different (ie read-only) directory to the changelog and the  
changelog directory were the default (since it really pretty much has  
to be read-write). Saving the image (if allowed by the settings of  
the system) would be to the known writable directory. This might be a  
scheme for some embedded devices with limited writable storage, for  
example.


tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange Opcodes: FART: Fill Accumulator from Result if True



Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Bert Freudenberg
In reply to this post by Lex Spoon-3

On Feb 16, 2007, at 17:20 , Lex Spoon wrote:

> "David T. Lewis" <[hidden email]> writes:
>>>> On Unix, "FileDirectory default" gives you the Unix cwd.
>>>
>>> No. It gives you the image directory.
>>
>> There is a "current working directory" introduced into CommandShell,
>> but as Bert says is a concept that does not exist in Squeak, so it
>> had to be added. Furthermore, it works on a per-volume basis in  
>> Windows
>> (C: drive versus D: drive, etc), so it's not clear that this is a
>> very portable concept.
>
> I see.  In the example script header I posted, they would be the same
> directory, but if you reuse an image in a stock location then they
> would be different.
>
> Why is the default directory set to the image's directory, anyway?
> That seems like zero bits of information: you can already compute it
> from the image's filename.  Additionally, isn't the most sensible
> "default directory" the same as the "default directory" (cwd) of the
> calling process?

No. When you launch by double-clicking an image, the CWD can be  
anything.

Besides, there are quite a few places in the image that assume image  
dir equals default dir. IIRC image saving goes nuts as well as source  
condensing etc. if the two differ.

But even if we wanted to change this, you would need to find a way to  
pass the CWD to the image. Or change the in-image code to pass  
relative paths down into the primitives - bypassing the default file  
dir completely ...

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

keith1y
In reply to this post by Bert Freudenberg
Bert Freudenberg wrote:

>
> On Feb 16, 2007, at 11:21 , Keith Hodges wrote:
>
>> Addendum, FYI the output of
>>
>> squeak -- Script +help
>>
>> from the command line 'Launcher' enabled image (see previous email)
>> gives the following overview of the resources available from the
>> command line.
>
> What's the reasoning behind this? Why not simply allow Smalltalk code
> to be passed on the command line?
>
> - Bert -
It evolved this way. This interface provides the ability for an action
to know its context, i.e. I am being invoked on the command-line so this
is the interface that I present to the command-line context, this is how
I play in a command line world.

Keith


               
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Lex Spoon-3
In reply to this post by Bert Freudenberg
Bert Freudenberg <[hidden email]> writes:
> On Feb 16, 2007, at 17:20 , Lex Spoon wrote:
> > Why is the default directory set to the image's directory, anyway?
> > That seems like zero bits of information: you can already compute it
> > from the image's filename.  Additionally, isn't the most sensible
> > "default directory" the same as the "default directory" (cwd) of the
> > calling process?
>
> No. When you launch by double-clicking an image, the CWD can be
> anything.

True.  To clarify, the proposal is to use the calling process's
default directory if there is one, e.g. if you double click.  If the
calling process has nothing better to supply, then of course it can
specify the image's directory.


> Besides, there are quite a few places in the image that assume image
> dir equals default dir. IIRC image saving goes nuts as well as source
> condensing etc. if the two differ.
>
> But even if we wanted to change this, you would need to find a way to
> pass the CWD to the image. Or change the in-image code to pass
> relative paths down into the primitives - bypassing the default file
> dir completely ...


Okay, it looks hard to change given all the legacy.  It would be nice,
though, if the VM could pass in (a) the default directory, and (b) a
directory with the sources files.  These are useful concepts on just
about any platform imaginable, and so should not need relegating to an
optional plugin.

Given the status quo, though, I guess a Unixy script needs to do
something else.  There are options.  They can use OSProcess (which
likely they want to use, anyway!), or they could have the shell script
code pass in $PWD as an argument to the Squeak code.


-Lex



Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

J J-6
In reply to this post by Lex Spoon-3
>From: Lex Spoon <[hidden email]>
>Reply-To: The general-purpose Squeak developers
>list<[hidden email]>
>To: [hidden email]
>Subject: Re: Squeak scripts in UNIX
>Date: 13 Feb 2007 12:04:42 -0500
>
>A nit with your explanation, by the way: it's #!, not # by itself.
>The # is a "hash", and the ! is a "bang", and thus #! is "hashbang"
>which, now that you mention it, does sound like "shebang" :) .

A nit with your nit:  # is called hash, but it is also called sharp.  As in
musical keys (e.g. C#).  So #! is "sharp-bang" or "shu-bang".  :)

Oh and, yes scripting support would be ausome.

_________________________________________________________________
Mortgage rates as low as 4.625% - Refinance $150,000 loan for $579 a month.
Intro*Terms  
https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f6&disc=y&vers=743&s=4056&p=5117


Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

J J-6
In reply to this post by Bert Freudenberg
>From: Bert Freudenberg <[hidden email]>
>Reply-To: The general-purpose Squeak developers
>list<[hidden email]>
>To: The general-purpose Squeak developers
>list<[hidden email]>
>Subject: Re: Squeak scripts in UNIX
>Date: Wed, 14 Feb 2007 21:51:17 +0100
>
>
>>That said, that's very interesting that using the absolute path works
>>already.  Maybe the easiest thing, then, is to come up with some
>>shell-script magic to rewrite $0 into an absolute path.  Do any Unix
>>hackers here know how to do that?
>
>I was using this:
>
> case "$2" in
>    /*) DOCUMENT="$2"
> ;;
>    *) DOCUMENT="$PWD/$2"
> ;;
> esac

Or you could just go:

  "$(pwd)/$(basename $0)"

That should handle the case where $0 is absolute already.

_________________________________________________________________
Play Flexicon: the crossword game that feeds your brain. PLAY now for FREE. 
  http://zone.msn.com/en/flexicon/default.htm?icid=flexicon_hmtagline


Reply | Threaded
Open this post in threaded view
|

Re: Squeak scripts in UNIX

Bert Freudenberg
On Feb 24, 2007, at 20:21 , J J wrote:

>> From: Bert Freudenberg <[hidden email]>
>> Reply-To: The general-purpose Squeak developers list<squeak-
>> [hidden email]>
>> To: The general-purpose Squeak developers list<squeak-
>> [hidden email]>
>> Subject: Re: Squeak scripts in UNIX
>> Date: Wed, 14 Feb 2007 21:51:17 +0100
>>
>>
>>> That said, that's very interesting that using the absolute path  
>>> works
>>> already.  Maybe the easiest thing, then, is to come up with some
>>> shell-script magic to rewrite $0 into an absolute path.  Do any Unix
>>> hackers here know how to do that?
>>
>> I was using this:
>>
>> case "$2" in
>>    /*) DOCUMENT="$2"
>> ;;
>>    *) DOCUMENT="$PWD/$2"
>> ;;
>> esac
>
> Or you could just go:
>
>  "$(pwd)/$(basename $0)"
>
> That should handle the case where $0 is absolute already.

But not if you give a relative path to it, like ../bin/bla

- Bert -



12