[Patches] [ python-Patches-612111 ] quietly select between 'less' and 'more'

noreply@sourceforge.net noreply@sourceforge.net
Thu, 26 Sep 2002 00:24:59 -0700


Patches item #612111, was opened at 2002-09-20 06:24
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=612111&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Skip Montanaro (montanaro)
Summary: quietly select between 'less' and 'more'

Initial Comment:
On Unixoid systems without the 'less' command, executing 
'pydoc.help(mod)' emits:

    sh: less: not found

which is annoying.  The attached patch gets it to quietly look for 'less' 
and 'more'.  I don't know if the locateexe() function is entirely correct 
(especially considering Windows) or if there are other pagers available.

backport candidate?  I know this behavior exists in 2.1.3 and 2.2.1.  
Dunno if it's more than a wart though.



----------------------------------------------------------------------

>Comment By: Ka-Ping Yee (ping)
Date: 2002-09-26 00:24

Message:
Logged In: YES 
user_id=45338

> I was trying to
> address the issue of pydoc noisily informing me that 'less' was
> not available.

Right, yeah -- but the point i was trying to make is that it's
not just a simple matter of "this feature is missing because
the author never thought of it, so we'll just add it".
There's something more subtle going on here.

I tested it when i originally wrote it and i tested it again
now, and it works fine if my system doesn't have 'less'
(it tries 'more', and failing that it just dumps the text out
straight).  Looking at the code, i can't explain the
behaviour you're getting.  Have you figured out why
you're getting an error message?

About the patch, specifically: i'm generally skeptical
of doing this kind of LBYL test where the test is
different from the actual action needed.  What we
need to know is whether os.system('less') will
succeed, not whether you can find a file named 'less'
on the path with a particular mode.  Finding the
executable is the operating system's business.
I'd prefer to do a test run of os.system('less') and
notice whether that succeeds or fails (which is what
it currently does -- but for some reason it doesn't
work correctly in your setup, and should be made
more robust).

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2002-09-25 14:22

Message:
Logged In: YES 
user_id=33168

I think locateexe() will not work on MacOS 9, where os.sep
== ':'.  But I don't know how the path works on MacOS 9 or X.

locateexe() can't work on Windows if a path component has
C:\XXX.  Also, the path separator on Windows is ';'.  You
should probably doc that locateexe doesn't work on Windows,
or get it to work on Windows.  Right now, there's no problem
since locateexe() can't be called on windows or os2 now.

I would replace if os.path.isfile() with a try/except
OSError: because the file could exist, but could be a broken
symlink.  I think that may raise an exception now.

To answer Thomas, I think people might use less under
cygwin.  But I'm not sure what os.platform is when python is
built using cygwin.

All that said, I actually like the patch. :-)  So to try to
make those ramblings understandable, check/change
os.path.isfile(), doc/fix locateexe for windows, and check
with Jack, Just, or some other mac person how this would
work on a Mac.


----------------------------------------------------------------------

Comment By: Skip Montanaro (montanaro)
Date: 2002-09-24 14:03

Message:
Logged In: YES 
user_id=44345

skip> The attached patch gets it to quietly look for 'less'
ping> It also already does this.

Not quite.  In situations where no PAGER was set and less was not 
found, as I indicated it emitted "sh: less: not found".  That was the entire 
reason for submitting the patch.  I'm more than willing to accept that my 
patch was incomplete or incorrect in some way, but I was trying to 
address the issue of pydoc noisily informing me that 'less' was not 
available. 

S


----------------------------------------------------------------------

Comment By: Ka-Ping Yee (ping)
Date: 2002-09-24 13:54

Message:
Logged In: YES 
user_id=45338

> It should also honour the PAGER environment variable

It already does this.  Read the code.

> I would suggest simply call more on Windows.

It already does this.  Read the code.

> The attached patch gets it to quietly look for 'less' 

It also already does this.  If it's not working for you,
there must be a bug. Look at the code -- all of this
behaviour is right there in getpager() and has been
there ever since pydoc was first written.


----------------------------------------------------------------------

Comment By: Gerhard Häring (ghaering)
Date: 2002-09-24 11:36

Message:
Logged In: YES 
user_id=163326

It should also honour the PAGER environment variable, and
use it if available. I'm trying to be puristic for a minute:
we probably shouldn't support any nonstandard pagers like
less, view, most, etc. at all. That's what Unix has the
PAGER environment variable for, just like the EDITOR and
VISUAL ones. I'm certainly no puristic Unix user, but we
already have zillions of patches for the webbrowser module
to support the various Unix Web Browsers out there. We
should avoid to get into the same situation with pydoc.

----------------------------------------------------------------------

Comment By: Gerhard Häring (ghaering)
Date: 2002-09-24 11:36

Message:
Logged In: YES 
user_id=163326

It should also honour the PAGER environment variable, and
use it if available. I'm trying to be puristic for a minute:
we probably shouldn't support any nonstandard pagers like
less, view, most, etc. at all. That's what Unix has the
PAGER environment variable for, just like the EDITOR and
VISUAL ones. I'm certainly no puristic Unix user, but we
already have zillions of patches for the webbrowser module
to support the various Unix Web Browsers out there. We
should avoid to get into the same situation with pydoc.

----------------------------------------------------------------------

Comment By: Thomas Heller (theller)
Date: 2002-09-20 06:54

Message:
Logged In: YES 
user_id=11105

locateexe does not work on Windows (for several reasons).
Dunno if people install other pagers - I certainly don't.
And when they do, are they really named 'less'?

OTOH, more is in the PATH on every windows system, so I
would suggest simply call more on Windows.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=612111&group_id=5470