try except is not working while using hdfs command

0 votes

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                                       
  Inspired by: http://stackoverflow.com/a/600612 

  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

Mar 6 in Python by anonymous
24 views
Seems like some problem with the hdfs path. Could you please the post the path that you are using?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Raw_input method is not working in python3. How to use it?

raw_input is not supported anymore in python3. ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
93 views
0 votes
1 answer

'python' is not recognized as an internal or external command

I have met same issue when I ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,140 points
77 views
0 votes
1 answer

Global Send Keys - Input text which has '(' is not working

Global Send Keys internally uses System.Windows.Forms.SendKeys so special characters escaped. For more ...READ MORE

answered Nov 15, 2018 in Python by findingbugs
• 3,140 points
213 views
0 votes
1 answer
0 votes
1 answer

Why there is no do while loop in python

There is no do...while loop because there ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 56,140 points
71 views
0 votes
1 answer

Is there anyway to obtain the full abstract from a 'PUBmed' article using bioPython

Hey Charlie, it's certainly possible to pull ...READ MORE

answered Aug 23, 2018 in Python by ariaholic
• 7,320 points
195 views
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 9,490 points
1,845 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 9,490 points
160 views
0 votes
10 answers

hadoop fs -put command?

copy command can be used to copy files ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Sujay
9,164 views
0 votes
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,260 points
658 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.