2010-03-08 15:28:06 +03:00
|
|
|
import os
|
2011-01-03 10:54:10 +03:00
|
|
|
import commonware
|
|
|
|
|
|
|
|
log = commonware.log.getLogger('f.utils')
|
2010-03-08 15:28:06 +03:00
|
|
|
|
2010-10-01 22:25:56 +04:00
|
|
|
|
2011-01-03 10:48:43 +03:00
|
|
|
# from http://jimmyg.org/blog/2009/working-with-python-subprocess.html
|
2010-10-01 22:25:56 +04:00
|
|
|
def whereis(program):
|
|
|
|
for path in os.environ.get('PATH', '').split(':'):
|
|
|
|
if os.path.exists(os.path.join(path, program)) and \
|
|
|
|
not os.path.isdir(os.path.join(path, program)):
|
|
|
|
return os.path.join(path, program)
|
|
|
|
return None
|
2011-01-03 10:48:43 +03:00
|
|
|
|
|
|
|
|
|
|
|
def make_path(directory):
|
|
|
|
""" Create all needed directories on the path """
|
|
|
|
sections = directory.split('/')
|
|
|
|
path = '/'
|
|
|
|
dir_created = False
|
|
|
|
for d in sections:
|
|
|
|
path = os.path.join(path, d)
|
|
|
|
if path and not os.path.isdir(path):
|
|
|
|
dir_created = True
|
|
|
|
os.mkdir(path)
|
|
|
|
|
2011-01-03 10:54:10 +03:00
|
|
|
if dir_created:
|
|
|
|
log.debug('Directory created for %s', directory)
|
2011-01-03 10:48:43 +03:00
|
|
|
return dir_created
|