Re: symbolic links, aliases, cls clear

2006-05-03 Thread af . dingo
it would be nice if python provided a termcap or terminfo library,
wouldn't it?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-05-03 Thread Floyd L. Davidson
[EMAIL PROTECTED] wrote:
it would be nice if python provided a termcap or terminfo library,
wouldn't it?

Try import curses.

-- 
Floyd L. Davidsonhttp://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-15 Thread Chris F.A. Johnson
On 2006-04-13, Barry Margolin wrote:
 In article [EMAIL PROTECTED],
  Chris F.A. Johnson [EMAIL PROTECTED] wrote:

  In fact, my scripts are portable to other terminal types by use
  of files for each terminal, generated with tput. Using a
  different terminal is as easy as . /usr/share/term-sh/$TERM or
  something similar. I generated a lot of files a few years ago,
  but I have never had any call for them, so I'd have to hunt for
  them.

 So you've essentially reinvented the whole termcap/terminfo mechanism?

   No, I've used the termcap/terminfo mechanism via tput to create a
   more efficient (and customizable) method of terminal-dependent
   control.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread af . dingo
If I may recommend an alternative,

print \033[H\033[J

the ansi sequence to clear the screen.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Floyd L. Davidson
[EMAIL PROTECTED] wrote:
If I may recommend an alternative,

print \033[H\033[J

the ansi sequence to clear the screen.

Or so you would hope (however, that is *not* what you have listed!).

Unfortunately, it is poor practice to hard code such sequences.
Instead the proper sequence should be obtained from the
appropriate database (TERMINFO or TERMCAP), and the easy way to
do that is,

   tput clear

-- 
Floyd L. Davidsonhttp://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Floyd L. Davidson
mp [EMAIL PROTECTED] wrote:
i have a python program which attempts to call 'cls' but fails:

sh: line 1: cls: command not found

Hm...  (I don't program in Python, so precisely what is
happening isn't something I'm sure about).

But, note how that line starts with sh:!  That indicates it is
/bin/sh which is reporting an inability to find a cls
command.  It suggests that Python (like most other programming
languages) calls shell scripts using /bin/sh as the default
shell.

The problem is that unix has no command named cls.

i tried creating an alias from cls to clear in .profile, .cshrc, and
/etc/profile, but none of these options seem to work.

In /etc/profile and ~/.profile you will cause an alias to be
defined *for* *interactive* *login* *shells*.  But not for
non-interactive non-login shells, which is what you are invoking
with Python.  The reason is because aliases are not inherited by
sub-shells, and only interactive login shells read those two
files.

Hence your alias is never defined in the subshell your program
executes.

my conclusion is that a python program that is executing does not use
the shell (because it does not recognize shell aliases). is this
correct?

No.

should i use a symbolic link? if so, where should i place it?

No.

what is the difference between aliases and symbolic links?

Aliases are a mechanism used by a shell to define a command name
that executes a series of commands.  A symbolic link is a
directory entry that de-references another directory entry, so
that either entry points to the same actual file.

if i execute a command like 'clear' to clear the screen, where does the
shell look to find the command 'clear'?

It looks in locations specified by the PATH variable.  By
default that will be a minimal list defined by the login
program, but it might be significantly added to in the
/etc/profile or other shell init scripts.

The question you need to answer first is what happens if your
Python program tries to execute /clear/ rather than /cls/.  If
that works, then your PATH variable is set correctly.  If it
doesn't work, verify that there is in fact a program named
/clear/ that can be run from a shell command line.  Then figure
out how to set an appropriate PATH variable for your Python
program.

Note that if /clear/ does work, but you want this script to use
/cls/ so that it is portable to some silly OS where a /cls/
exists...  You can define a shell function (which will be
inherited by sub-shells) to look like this,

  function cls () {
 clear;
  }

And place it where ever is appropriate (/etc/profile is one place).

i'm using os x.

I don't know anything about it... :-)

-- 
Floyd L. Davidsonhttp://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Michael Paoli
Floyd L. Davidson wrote:
 [EMAIL PROTECTED] wrote:
 If I may recommend an alternative,
 print \033[H\033[J
 Unfortunately, it is poor practice to hard code such sequences.
 Instead the proper sequence should be obtained from the
 appropriate database (TERMINFO or TERMCAP), and the easy way to
 do that is,
tput clear

Or clear(1), as also mentioned earlier.  Yes, definitely don't want to
hardcode the sequence.  Definitely do use the appropriate terminal
capabilities database (terminfo or termcap) in the appropriate manner
(e.g. clear(1) or tput clear will handle that in the simple case of
shell accessible means to clear the screen).

Most UNIX(/LINUX/BSD/...) implementations support a large number of
terminal types.  E.g. on my system, I check and find that there are
1470 unique terminal types (descriptions) supported - and that's not
including multiple aliases for the same terminal type/description (but
it does count distinct names/files which have differing
configurations, even if they are for the same terminal - such as
changing certain options or behavior of a terminal, or using the
terminal in distinct modes).  Among those terminal types on my system,
I find 154 distinct means of clearing the screen.  Just for
illustrative purposes, here are the top 10 I find, with count of how
many distinct types (descriptions) use that particular sequence:
236 clear=\E[H\E[J,
120 clear=^L,
120 clear=\E[H\E[2J,
 64 clear=\EH\EJ,
 61 clear=\E[2J,
 42 clear=\E[H\E[J$156,
 38 clear=^Z,
 36 clear=\E[H\E[J$50,
 31 clear=\E[H\E[J$40,
 29 clear=\E[2J\E[H,
And of course, sending the wrong sequence (e.g. like trying some to
see what works) can be highly problematic - it can do very nasty
things to some terminals.  E.g. I own one terminal, which among
sequences it supports, is one which effectively says interpret the
following hexadecimal character pairs as bytes, load them into RAM,
and execute them - a relatively sure-fire way to crash the terminal if
it is sent garbage (I used to run into that and other problems with
some BBS systems that would presume everyone must be running something
ANSI capable or that it was safe to do other tests such as see if
certain sequences would render a blue square on one's screen).

references:
system call/function, in various programming languages
clear(1)
tput(1)
terminfo(5)
termcap(5)
news:[EMAIL PROTECTED]
news:[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Keith Thompson
[EMAIL PROTECTED] (Floyd L. Davidson) writes:
 [EMAIL PROTECTED] wrote:
If I may recommend an alternative,

print \033[H\033[J

the ansi sequence to clear the screen.

 Or so you would hope (however, that is *not* what you have listed!).

 Unfortunately, it is poor practice to hard code such sequences.
 Instead the proper sequence should be obtained from the
 appropriate database (TERMINFO or TERMCAP), and the easy way to
 do that is,

tput clear

(Or clear.)

On the other hand, I think it's been at least a decade since I've used
a terminal or emulator that's not VT100-compatible (i.e., accepts ANSI
control sequences).

Of course, I'll run into one the day after I start writing code that
depends on that assumption.

-- 
Keith Thompson (The_Other_Keith) [EMAIL PROTECTED]  http://www.ghoti.net/~kst
San Diego Supercomputer Center *  http://users.sdsc.edu/~kst
We must do something.  This is something.  Therefore, we must do this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, Floyd L. Davidson wrote:
 [EMAIL PROTECTED] wrote:
If I may recommend an alternative,

print \033[H\033[J

the ansi sequence to clear the screen.

 Or so you would hope (however, that is *not* what you have listed!).

 Unfortunately, it is poor practice to hard code such sequences.

   I was bitten by that shortly after I started shell scripting.
   However, since all such code was isolated in functions, converting
   to a new terminal type was simple -- and quick.

   These days, the ISO-6429 standard (almost the same as the older
   ANSI x3.64) is so close to universal that I don't bother writing
   for anything else any more. If the need arises, I'll do it, but it
   will be simple to do, and much faster (both in coding and script
   execution) than trying to accommodate all terminals from the start.

 Instead the proper sequence should be obtained from the
 appropriate database (TERMINFO or TERMCAP), and the easy way to
 do that is,

tput clear

   I still have a system which does not have tput.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Floyd L. Davidson
Keith Thompson [EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] (Floyd L. Davidson) writes:
 [EMAIL PROTECTED] wrote:
If I may recommend an alternative,

print \033[H\033[J

the ansi sequence to clear the screen.

 Or so you would hope (however, that is *not* what you have listed!).

 Unfortunately, it is poor practice to hard code such sequences.
 Instead the proper sequence should be obtained from the
 appropriate database (TERMINFO or TERMCAP), and the easy way to
 do that is,

tput clear

(Or clear.)

But /clear/ merely uses tput clear.

On the other hand, I think it's been at least a decade since I've used
a terminal or emulator that's not VT100-compatible (i.e., accepts ANSI
control sequences).

Of course, I'll run into one the day after I start writing code that
depends on that assumption.

However, if you check out the various TERMINFO database entries for an
assortment of VT100-compatible terminals, you *will* find variation!

Plus, if a user has customized a terminal database, for who knows what
reason...

-- 
Floyd L. Davidsonhttp://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, Floyd L. Davidson wrote:
 Keith Thompson [EMAIL PROTECTED] wrote:
tput clear

(Or clear.)

 But /clear/ merely uses tput clear.

   Not on systems without tput.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread jpd
Begin  [EMAIL PROTECTED]
On 2006-04-12, Chris F.A. Johnson [EMAIL PROTECTED] wrote:
These days, the ISO-6429 standard (almost the same as the older
ANSI x3.64) is so close to universal that I don't bother writing
for anything else any more.

Oh, wonderful. ``All the world's a vax^W^WISO-6429 compatible'' all over
again.


If the need arises, I'll do it, but it will be simple to do, and
much faster (both in coding and script execution) than trying to
accommodate all terminals from the start.

Yes, why use a perfectly good abstraction when you can hardcode stuff.


I still have a system which does not have tput.

And that justifies everything else. Of course.


-- 
  j p d (at) d s b (dot) t u d e l f t (dot) n l .
  This message was originally posted on Usenet in plain text.
  Any other representation, additions, or changes do not have my
  consent and may be a violation of international copyright law.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, jpd wrote:
 Begin  [EMAIL PROTECTED]
 On 2006-04-12, Chris F.A. Johnson [EMAIL PROTECTED] wrote:
These days, the ISO-6429 standard (almost the same as the older
ANSI x3.64) is so close to universal that I don't bother writing
for anything else any more.

 Oh, wonderful. ``All the world's a vax^W^WISO-6429 compatible'' all over
 again.

If the need arises, I'll do it, but it will be simple to do, and
much faster (both in coding and script execution) than trying to
accommodate all terminals from the start.

 Yes, why use a perfectly good abstraction when you can hardcode stuff.

   If it were perfectly good, there would be no question; however,
   it's not.

I still have a system which does not have tput.

 And that justifies everything else. Of course.

   If I want to write portable scripts, then yes, it does.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Floyd L. Davidson
Chris F.A. Johnson [EMAIL PROTECTED] wrote:
On 2006-04-12, Floyd L. Davidson wrote:
 Keith Thompson [EMAIL PROTECTED] wrote:
tput clear

(Or clear.)

 But /clear/ merely uses tput clear.

   Not on systems without tput.

Shoot that thing, and put it (and yourself) out of its misery.

-- 
Floyd L. Davidsonhttp://www.apaflo.com/floyd_davidson
Ukpeagvik (Barrow, Alaska) [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Christos Georgiou
On Wed, 12 Apr 2006 15:59:05 -0400, rumours say that Chris F.A. Johnson
[EMAIL PROTECTED] might have written:

I still have a system which does not have tput.

 And that justifies everything else. Of course.

   If I want to write portable scripts, then yes, it does.

Well, either port your system out of the window or port tput.c to your
system and then start writing portable scripts.  tput is part of the POSIX
1003.1 standard, and guess what the 'P' stands for in POSIX.

If you insist, I will retort to using Terry Pratchett references.
-- 
TZOTZIOY, I speak England very best.
Dear Paul,
please stop spamming us.
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Chris F.A. Johnson
On 2006-04-12, Christos Georgiou wrote:
 On Wed, 12 Apr 2006 15:59:05 -0400, rumours say that Chris F.A. Johnson
[EMAIL PROTECTED] might have written:

I still have a system which does not have tput.

 And that justifies everything else. Of course.

   If I want to write portable scripts, then yes, it does.

 Well, either port your system out of the window or port tput.c to your
 system and then start writing portable scripts.  tput is part of the POSIX
 1003.1 standard, and guess what the 'P' stands for in POSIX.

 It may be part of the POSIX standard, but there's nothing in the
 POSIX definition of tput that provides for cursor positioning or
 font attributes. The only defined operands are clear, init and
 reset.

 In fact, my scripts are portable to other terminal types by use
 of files for each terminal, generated with tput. Using a
 different terminal is as easy as . /usr/share/term-sh/$TERM or
 something similar. I generated a lot of files a few years ago,
 but I have never had any call for them, so I'd have to hunt for
 them.

 If you insist, I will retort to using Terry Pratchett references.

 UNCLE!

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-12 Thread Barry Margolin
In article [EMAIL PROTECTED],
 Chris F.A. Johnson [EMAIL PROTECTED] wrote:

  In fact, my scripts are portable to other terminal types by use
  of files for each terminal, generated with tput. Using a
  different terminal is as easy as . /usr/share/term-sh/$TERM or
  something similar. I generated a lot of files a few years ago,
  but I have never had any call for them, so I'd have to hunt for
  them.

So you've essentially reinvented the whole termcap/terminfo mechanism?

-- 
Barry Margolin, [EMAIL PROTECTED]
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-04-04 Thread Pankaj
its true for the processes, gone to the system mode and from there the
process is not considering the shell variable any more.

In case of deamons also it is the same case. For Phython programs, I am
not sure , may they are also nohops, so might be not accessing the
shell variables. But i think you have defined the alias to some other
place the error is reported by shell that cls not found.

This could be investigated if you do some tests with the system. Like
alias is shell script you can open it and read it , how it invokes the
command for creating aliases. etc etc.

Alias: When the shell is in picture it directly replaces the string
cls to clear and execute the clear.

Symbolic links: are reference to the inode of the actual files, so it
should work in your case.

just run
#which clear
(O/P , you will get the location of binary say /usr/bin/clear)

Now you can create the symbolic link named as cls at location
/usr/bin. this symbolic link should be a soft link to /usr/bin/clear.
 you can also put the symbolic links to any of the location that is
displayed by $PATH variable.

for any command you execute in shell, it functions in following order:
(Not exactly the same, need to confirm, i might miss some of the steps)

1) check with the shell variable(whether any alias to this command
exists or not!)
2) search it in the locations $PATH and execute the command is it is
found.
so on...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-30 Thread Michael Paoli
mp wrote:
 i have a python program which attempts to call 'cls' but fails:
 sh: line 1: cls: command not found
 i'm using os x.

[Note Followup-to: severely trimmed]

I'd guestimate (those more familiar with python can probably fill in
more relevant python specific details) that the python program is
probably doing something like:
system(cls)
... or whatever the python-specific way of writing something like that
is.  Most likely that was written, intended for some Microsoft
DOS/Windows/XP or similar type of operating system - where CLS is a
legitimate command (to clear the screen).  On UNIX (and probably also
OS X), there is no cls as a standard command, but there is the quite
standard command clear, to clear the terminal screen.

In the land of UNIX, most languages implement the system() function or
equivalent, by typically fork(2)ing and exec(3)ing (at least one of the
exec(3) family of calls), generally invoking the or a default shell
(typically /bin/sh) with a first option argument of -c, and then the
argument to system passed as one single string as the other argument to
the shell.  It would seem likely that python was smart enough (of
course) to know on UNIX to implement system() as sh -c ..., rather than
something like COMMAND /C ... or CMD /C ... as it would likely do on
DOS/Windows/XP or similar.  But of course python probably has no clue
what the cls is that's handed to it with system(), and likely just
blindly passes it on to the shell.  The diagnostic you got would also
seem to imply that's what happened (the shell (sh) couldn't find the
cls command). ... as a matter of fact, if I try that on Debian
GNU/Linux 3.1 (technically not UNIX, but neither is OS X, but for
practical purposes they're both quite sufficiently close), I get
results that would appear exceedingly consistent with the hypothesis I
put forth:
$ sh -c cls
sh: line 1: cls: command not found

If it's desired to have the python program function as close to its
(apparent) original intent as feasible, it may be desirable to:
have it test the operating system, and if it is UNIX or similar, use
clear, instead of cls ... or if one wants to port/adapt it to UNIX
(and OS X, etc.), with no need or intention to move it back and forth
or among significantly different operating systems, then perhaps
consider simply replacing the system(cls) with system(clear), or
whatever the precise suitable change in the python code would be.
It would probably also be worth inspecting the code for other
occurrences of system() that may also need to be adjusted or changed.

Note also that some languages (e.g. Perl) will potentially take
shortcuts with the system() function.  For example, with Perl
(paraphrasing and perhaps over-simplifying a bit) if Perl sees no
need or reason to have to use the overhead of the shell to invoke the
system() function, it will just quite directly (after the fork(2))
exec(3) the command, setting the argument(s) suitably.  Python may
(or may not) try similar shortcuts.  For example, CLS, on DOS, etc.,
is internal to the shell (command interpreter), so, if python
didn't find an external CLS command, it would have to pass it to the
shell, hoping the shell would know what to do with it.  That would
happen to work with DOS, but would generally fail on UNIX (where cls
would generally not exist as a command, and wouldn't be built-in to
the shell).

-- 
http://mail.python.org/mailman/listinfo/python-list


symbolic links, aliases, cls clear

2006-03-29 Thread mp
i have a python program which attempts to call 'cls' but fails:

sh: line 1: cls: command not found

i tried creating an alias from cls to clear in .profile, .cshrc, and
/etc/profile, but none of these options seem to work.

my conclusion is that a python program that is executing does not use
the shell (because it does not recognize shell aliases). is this
correct?

should i use a symbolic link? if so, where should i place it?

what is the difference between aliases and symbolic links?

if i execute a command like 'clear' to clear the screen, where does the
shell look to find the command 'clear'?

i'm using os x.

thanks
mp

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-29 Thread Keith Thompson
mp [EMAIL PROTECTED] writes:
 i have a python program which attempts to call 'cls' but fails:

 sh: line 1: cls: command not found

 i tried creating an alias from cls to clear in .profile, .cshrc, and
 /etc/profile, but none of these options seem to work.

 my conclusion is that a python program that is executing does not use
 the shell (because it does not recognize shell aliases). is this
 correct?

Yes.

 should i use a symbolic link? if so, where should i place it?

You could, but I don't think it's the best solution.

 what is the difference between aliases and symbolic links?

Aliases exist only in a shell.  Symbolic links exist in the file
system.

 if i execute a command like 'clear' to clear the screen, where does the
 shell look to find the command 'clear'?

Generally it searches $PATH for an executable file called clear.

I don't know Python very well (note the cross-post), but if it
provides a way to detect which operating system you're running on, you
could execute cls if you're on Windows, or clear if you're on a
Unix-like system.  Or there might be some Python library with a
clear-screen function.

Are you sure you want to clear the screen?  If I run your program and
it clears my screen for me, it could be erasing significant
information.  If you want complete control over the screen, you should
probably use something like curses or ncurses (there may be a Python
interface to it).

-- 
Keith Thompson (The_Other_Keith) [EMAIL PROTECTED]  http://www.ghoti.net/~kst
San Diego Supercomputer Center *  http://users.sdsc.edu/~kst
We must do something.  This is something.  Therefore, we must do this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-29 Thread Chris F.A. Johnson
On 2006-03-29, mp wrote:
 i have a python program which attempts to call 'cls' but fails:

 sh: line 1: cls: command not found

 i tried creating an alias from cls to clear in .profile, .cshrc, and
 /etc/profile, but none of these options seem to work.

   Why not call 'clear', since 'cls' does not exist?

 my conclusion is that a python program that is executing does not use
 the shell (because it does not recognize shell aliases). is this
 correct?

   Even shell scripts do not normally expand aliases.

 should i use a symbolic link? if so, where should i place it?

 what is the difference between aliases and symbolic links?

   What's the difference between a raven and a writing desk?

 if i execute a command like 'clear' to clear the screen, where does the
 shell look to find the command 'clear'?

   In a directory listed in the PATH variable.

-- 
   Chris F.A. Johnson, author   |http://cfaj.freeshell.org
   Shell Scripting Recipes: |  My code in this post, if any,
   A Problem-Solution Approach  |  is released under the
   2005, Apress | GNU General Public Licence
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: symbolic links, aliases, cls clear

2006-03-29 Thread SM Ryan
mp [EMAIL PROTECTED] wrote:
# i have a python program which attempts to call 'cls' but fails:
# 
# sh: line 1: cls: command not found
# 
# i tried creating an alias from cls to clear in .profile, .cshrc, and
# /etc/profile, but none of these options seem to work.
# 
# my conclusion is that a python program that is executing does not use
# the shell (because it does not recognize shell aliases). is this
# correct?

Shell command alias or Mac OSX file alias, like a Finder Make Alias?

A file alias is similar to a soft link except it has both path
and device/inode like information so that it can still identify
a renamed file. However aliasses are handled at the toolbox level
instead of the kernel, so that unix only code cannot resolve them.


//  readalias - Resolve Finder alias files to the actual
//file, if it can be found. The interface is modelled
//after readlink. If the original is not alias
//or could not be resolved, return 0 and set errno.
//Otherwise return a mallocked string with the
//actual file path; caller must free.
//
//  On non-macintosh systems, this always returns an
//  error.

#ifdef ALIAS
  #include CoreFoundation/CoreFoundation.h
  #include ApplicationServices/ApplicationServices.h

  static char *readalias(char *original) {
int ec = 0;
CFStringRef path = 0;
CFStringRef resolvedPath = 0;
CFURLRef url = 0;
CFURLRef resolvedUrl = 0;
FSRef fsRef;
char *s = 0;
if (!(path=CFStringCreateWithCString(NULL,original,kCFStringEncodingUTF8))) 
{
  ec = EFAULT; goto exit;
}
if (!(url=CFURLCreateWithFileSystemPath(NULL,path,kCFURLPOSIXPathStyle,0))) 
{
  ec = EFAULT; goto exit;
}
if (!CFURLGetFSRef(url,fsRef)) {
  ec = ENOENT; goto exit;
}
Boolean targetIsFolder,wasAliased;
if ((ec=FSResolveAliasFile(fsRef,true,targetIsFolder,wasAliased))) {
  goto exit;
}
if (!wasAliased) {
  ec = EINVAL; goto exit;
}
if (!(resolvedUrl=CFURLCreateFromFSRef(NULL,fsRef))) {
  ec = EFAULT; goto exit;
}
if (!(resolvedPath = 
CFURLCopyFileSystemPath(resolvedUrl,kCFURLPOSIXPathStyle))) {
  ec = EFAULT; goto exit;
}
s = (char*)CFStringGetCStringPtr(resolvedPath,kCFStringEncodingUTF8);
if (s) {
  s = strcpy(malloc(strlen(s)+1),s);
}else {
  int n = 3*CFStringGetLength(resolvedPath) + 1; s = malloc(n);
  if (CFStringGetCString(resolvedPath,s,n,kCFStringEncodingUTF8)) {
s = realloc(s,strlen(s)+1);
  }else {
ec = EFAULT; goto exit;
  }
}
  exit:
if (path) CFRelease(path);
if (resolvedPath) CFRelease(resolvedPath);
if (url) CFRelease(url);
if (resolvedUrl) CFRelease(resolvedUrl);
if (ec) {
  if (ec0) ec = ENOENT;
  errno = ec; free(s); s = 0;
}
return s;
  }
#else
  static char *readalias(char *original) {
errno = EINVAL;
return 0;
  }
#endif

--
SM Ryan http://www.rawbw.com/~wyrmwif/
But I do believe in this.
-- 
http://mail.python.org/mailman/listinfo/python-list