os_dep.py revision 0afbb6369aa5aa9a75ea67dd9e95ec4b21c0c181
1#!/usr/bin/python 2import os 3 4""" 5One day, when this module grows up, it might actually try to fix things. 6'apt-cache search | apt-get install' ... or a less terrifying version of 7the same. With added distro-independant pixie dust. 8""" 9 10def command(cmd): 11 # this could use '/usr/bin/which', I suppose. But this seems simpler 12 for dir in os.environ['PATH'].split(':'): 13 file = os.path.join(dir, cmd) 14 if os.path.exists(file): 15 return file 16 raise ValueError('Missing command: %s' % cmd) 17 18 19def commands(*cmds): 20 results = [] 21 for cmd in cmds: 22 results.append(command(cmd)) 23 24 25def library(lib): 26 lddirs = [x.rstrip() for x in open('/etc/ld.so.conf', 'r').readlines()] 27 for dir in ['/lib', '/usr/lib'] + lddirs: 28 file = os.path.join(dir, lib) 29 if os.path.exists(file): 30 return file 31 raise ValueError('Missing library: %s' % lib) 32 33 34def libraries(*libs): 35 results = [] 36 for lib in libs: 37 results.append(library(lib)) 38