runtime location discovery

Geoff Gerrietts geoff at gerrietts.net
Mon Apr 1 17:19:22 EST 2002


Quoting Geoff Gerrietts (geoff at gerrietts.net):
> Now I can go look for symlinks and resolve them, that's not a problem.
> But a hard link would create the same problem all over again. So I'm
> curious -- this can't be an uncommon hurdle to hop. How have other
> people solved the problem?

I've spent some time thinking about this and working at it, and I've
come to the conclusion that no solution is a sure-fire winner. I've
got two ideas toward achieving the goal that I'm pretty happy with.

First: start the program with a shell-script wrapper that is
configured to know where the program is installed. The shell script
can be linked or symlinked to or whatever else, and it won't cause a
problem. I'm not entirely pleased with this solution, since all it
does is move the deterministic configuration step out to the shell
script, but it's acceptable.

Second: put an __init__.py in the images directory and import it --
then use images.__path__[0] as the prefix for my resource loads. That
solves the sys.argv[0] problem without having to special-case for
symlinks, but it still breaks on a hard link.

Of course, I can't even rely on os.path[''] when there's a hard link
involved, which is really the whole reason for the "First" part of the
solution.

I've heard it said that the best way to get a response on the internet
is to post the wrong information, so I'll make a pleasantly audacious
claim in closing: this is the best possible way to address the problem
described. I almost believe that's true, so argue with me. Please. :)

Thanks,
--G.

-- 
Geoff Gerrietts             "If life were measured by accomplishments, 
<geoff at gerrietts net>     most of us would die in infancy." 
http://www.gerrietts.net/       --A.P. Gouthey




More information about the Python-list mailing list