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

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

View File

@ -1,6 +1,7 @@
import logging, os import logging, os
from subprocess import run, PIPE, CalledProcessError from subprocess import run, PIPE, CalledProcessError
from logging.handlers import TimedRotatingFileHandler, SMTPHandler from logging.handlers import TimedRotatingFileHandler, SMTPHandler
from auxilary import mkdirSafe
''' '''
Logger conventions Logger conventions
@ -44,17 +45,11 @@ class GlusterFSHandler(TimedRotatingFileHandler):
self._volume = volume self._volume = volume
self._options = options 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() self._mount()
logdest = mountpoint + '/logs'
mkdirSafe(logdest, logger)
super().__init__(logdest + '/pyledriver-log', when='midnight') super().__init__(logdest + '/pyledriver-log', when='midnight')
fmt = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s') fmt = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')