pyledriver/auxilary.py

30 lines
784 B
Python
Raw Normal View History

'''
Various helper functions and classes
'''
import time, os
2017-05-31 00:54:00 -04:00
def mkdirSafe(path, logger):
'''
Makes new dir if path does not exist, and aborts program if path exists and
path is a file not a dir. Else does nothing
'''
if not os.path.exists(path):
os.mkdir(path)
elif os.path.isfile(path):
logger.error('%s is present but is a file (vs a directory). ' \
'Please (re)move this file to prevent data loss', path)
raise SystemExit
def waitForPath(path, logger, timeout=30):
2017-05-31 00:41:56 -04:00
'''
Waits for a path to appear. Useful for procfs and sysfs where devices
regularly (dis)appear. Timeout given in seconds
'''
2017-05-30 01:00:23 -04:00
for i in range(0, timeout):
if os.path.exists(path):
return
time.sleep(1)
logger.error('Could not find %s after %s seconds', path, timeout)
2017-05-30 02:11:15 -04:00
raise SystemExit