Hi,
I am trying to run following things in code, but it's not working
def create_if_not_exists(dir_fullpath):
"""Creates a given directory if it doesn't exist yet
Args:
dir_fullpath: full path to the directory
if dir_fullpath.startswith("/hdfs") :
print 'Entering hdfs area'
hdfsdir = re.sub('/hdfs','',dir_fullpath)
cmd = 'hdfs dfs -mkdir -p %s' %hdfsdir
try:
os.system(cmd)
print ' directory is created successfully'
except OSError as exc:
print 'error'
print 'directory is not created'
cmd = 'hdfs dfs -test -d %s' %hdfsdir
direxist = os.system(cmd)==0
if exc.errno == errno.EEXIST and direxist :
pass
else:
raise
else :
print 'Entering home dir'
cmd = 'mkdir %s' %dir_fullpath
try :
os.system(cmd)
#os.makedirs(dir_fullpath)
print ' directory is created succesfully'
except OSError as exc:
print 'directory is not created'
if exc.errno == errno.EEXIST and os.path.isdir(dir_fullpath):
pass
else:
return
while it works when directory name starts w/ 'home ', but it gets stuck, try:
os.system(cmd)
print ' directory is created successfully' when directory name starts w/ '/hdfs'. Could you please help me to solve this problem?
Thanks