locate executables for different platforms

Andrea Crotti andrea.crotti.0 at gmail.com
Mon Oct 31 10:24:40 EDT 2011


On 10/31/2011 02:00 PM, Andrea Crotti wrote:
> Suppose that I have a project which (should be)/is multiplatform in 
> python,
> which, however, uses some executables as black-boxes.
>
> These executables are platform-dependent and at the moment they're just
> thrown inside the same egg, and using pkg_resources to get the path.
>
> I would like to rewrite this thing being able to:
> - detect the OS
> - find the right executable version
> - get the path and run it
>
> It would be nice to still be able to use pkg_resources, but at that 
> point I think
> I would need to store all the executables in another egg, is that 
> correct?
> Is there already something available to manage external multi-platform 
> executables?
>
> Thanks,
> Andrea

The most simple possible way I can think of to solve this problem would 
be, to create
a directory for each executable, and in each directory the executable 
with the platform
in the name, like:

- exec1:
   + exec1-linux2
   + exec1-darwin
...

And to look up would be very simple (as below), but I feel that is not 
very smart...


import sys

from os import path

BASE_DIR = '.'

exec_name = sys.argv[1]

assert path.isdir(exec_name)

plat = sys.platform

name_ex = "%s-%s" % (exec_name, plat)
if plat == 'win32':
     name_ex += '.exe'

res_ex = path.join(exec_name, name_ex)
assert path.isfile(res_ex)
print path.abspath(res_ex)




More information about the Python-list mailing list