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
41 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
121 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,520 points
108 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
391 views
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26 in Python by Neel
• 3,010 points
47 views
0 votes
0 answers

Why is selenium css and xpath selector not working?

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or ...READ MORE

Jul 18 in Python by Waseem
• 4,480 points
32 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
• 10,670 points
2,738 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
• 10,670 points
289 views
0 votes
10 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
13,571 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,240 points
994 views