Files
py-eagle-mqtt/Docker/src/python/tHome/util/path.py
erichardso d880f44ca6 Moved Docker stuff to "Docker" folder
Created k8s folder for k8s stuff
Added early-stage service.yaml for K8s deployment
2018-08-28 11:51:23 -07:00

45 lines
1.3 KiB
Python

#===========================================================================
#
# File and directory utilities.
#
#===========================================================================
import os
import os.path
from .Error import Error
#===========================================================================
def makeDirs( fileName ):
"""TODO: docs
"""
try:
d = os.path.dirname( fileName )
if d and not os.path.exists( d ):
os.makedirs( d )
except ( IOError, OSError ) as e:
msg = "Error trying to create intermediate directories for the file: " \
"'%s'" % ( fileName )
Error.raiseException( e, msg )
#===========================================================================
def expand( filePath, fileName=None ):
"""Combine a directory and file name and expand env variables and ~.
A full path can be input in filePath. Or a directory can be input
in filePath and a file name input in fileName.
"""
if fileName:
filePath = os.path.join( filePath, fileName )
filePath = str( filePath )
if "$" in filePath:
filePath = os.path.expandvars( filePath )
if "~" in filePath:
filePath = os.path.expanduser( filePath )
return filePath
#===========================================================================