move mkdirSafe to auxilary

This commit is contained in:
petrucci4prez 2017-05-31 00:54:00 -04:00
parent cff80a8d91
commit 17234848ac
2 changed files with 17 additions and 10 deletions

View File

@ -61,7 +61,19 @@ class CountdownTimer(Thread):
def __del__(self):
self.stop()
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=None, timeout=30):
'''
Waits for a path to appear. Useful for procfs and sysfs where devices

View File

@ -1,6 +1,7 @@
import logging, os
from subprocess import run, PIPE, CalledProcessError
from logging.handlers import TimedRotatingFileHandler, SMTPHandler
from auxilary import mkdirSafe
'''
Logger conventions
@ -44,16 +45,10 @@ class GlusterFSHandler(TimedRotatingFileHandler):
self._volume = volume
self._options = options
logdest = mountpoint + '/logs'
if not os.path.exists(logdest):
os.mkdir(logdest)
elif os.path.isfile(logdest):
logger.error('%s is present but is a file (vs a directory). ' \
'Please (re)move this file to prevent data loss', logdest)
raise SystemExit
self._mount()
logdest = mountpoint + '/logs'
mkdirSafe(logdest, logger)
super().__init__(logdest + '/pyledriver-log', when='midnight')