move mkdirSafe to auxilary
This commit is contained in:
parent
cff80a8d91
commit
17234848ac
14
auxilary.py
14
auxilary.py
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
Loading…
Reference in New Issue