From: Tim Daneliuk on
Given a program 'foo' that takes a command line argument '-I
includefile', I want to be able to look for 'includefile' in a path
specified in an environment variable, 'FOOPATH'.

I'd like a semantic that says:

"If 'includefile' contains one or more path separator characters,
ignore 'FOOPATH'. If it contains no path separators, look for it in
the paths specified by 'FOOPATH', beginning with the leftmost path
first."

Is there a standard Pythonic idiom for doing this or do I need to cook
up my own.


TIA,
--
----------------------------------------------------------------------------
Tim Daneliuk tundra(a)tundraware.com
PGP Key: http://www.tundraware.com/PGP/

From: Chris Rebert on
On Wed, Jun 23, 2010 at 3:27 PM, Tim Daneliuk <tundra(a)tundraware.com> wrote:
> Given a program 'foo' that takes a command line argument '-I
> includefile', I want to be able to look for 'includefile' in a path
> specified in an environment variable, 'FOOPATH'.
>
> I'd like a semantic that says:
>
>  "If 'includefile' contains one or more path separator characters,
>   ignore 'FOOPATH'. If it contains no path separators, look for it in
>   the paths specified by 'FOOPATH', beginning with the leftmost path
>   first."
>
> Is there a standard Pythonic idiom for doing this or do I need to cook
> up my own.

Cook your own. Also, I certainly wouldn't call something this complex
a mere idiom.
You will find optparse, os.sep, and os.walk helpful in writing your code.

Cheers,
Chris
--
http://blog.rebertia.com
From: Nobody on
On Wed, 23 Jun 2010 17:27:16 -0500, Tim Daneliuk wrote:

> Given a program 'foo' that takes a command line argument '-I
> includefile', I want to be able to look for 'includefile' in a path
> specified in an environment variable, 'FOOPATH'.
>
> I'd like a semantic that says:
>
> "If 'includefile' contains one or more path separator characters,
> ignore 'FOOPATH'. If it contains no path separators, look for it in
> the paths specified by 'FOOPATH', beginning with the leftmost path
> first."
>
> Is there a standard Pythonic idiom for doing this or do I need to cook
> up my own.

There isn't an idiom.

There are a surprising number of choices for such a simple task, e.g.
whether the search path is used for relative paths containing a separator,
whether you stop at the first file which exists or the first file which
meets other criteria (e.g. suitable permissions), whether default
locations come first or last, what happens if a default location is
included in the search path, etc.

From: Gregory Ewing on
Tim Daneliuk wrote:
> "If 'includefile' contains one or more path separator characters,
> ignore 'FOOPATH'.

Are you sure that's exactly what you want? Usually with
such things the distinction is absolute vs. relative,
not whether there is more than one pathname component.
E.g. in a C file,

#include "GL/gl.h"

will search the include path for a directory called
"GL" containing a file called "gl.h".

--
Greg
From: Tim Daneliuk on
On 6/24/2010 2:57 AM, Gregory Ewing wrote:
> Tim Daneliuk wrote:
>> "If 'includefile' contains one or more path separator characters,
>> ignore 'FOOPATH'.
>
> Are you sure that's exactly what you want? Usually with
> such things the distinction is absolute vs. relative,
> not whether there is more than one pathname component.
> E.g. in a C file,
>
> #include "GL/gl.h"
>
> will search the include path for a directory called
> "GL" containing a file called "gl.h".
>

Point well taken, thanks.

--
----------------------------------------------------------------------------
Tim Daneliuk tundra(a)tundraware.com
PGP Key: http://www.tundraware.com/PGP/