src/cm/utils/system.py
changeset 0 40c8f766c9b8
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     1 # taken from plone
       
     2 
       
     3 import os
       
     4 
       
     5 bin_search_path = [
       
     6     '/usr/bin',
       
     7     '/usr/local/bin',
       
     8     ]
       
     9 
       
    10 class MissingBinary(Exception): pass
       
    11 
       
    12 def bin_search(binary):
       
    13     """search the bin_search_path  for a given binary
       
    14     returning its fullname or None"""
       
    15     result = None
       
    16     mode   = os.R_OK | os.X_OK
       
    17     for p in bin_search_path:
       
    18         path = os.path.join(p, binary)
       
    19         if os.access(path, mode) == 1:
       
    20             result = path
       
    21             break
       
    22     else:
       
    23         raise MissingBinary('Unable to find binary "%s"' % binary)
       
    24     return result