You can check the action IO error by using the errno module and the IOError's errno member variable. It would be nice if that worked for IOErrors when working with HDFS. I don't know hadoop well enough, but it might even be possible to get this from the exit code of the process.
Essentially I wanted to write:
try:
hadoopy.put('/root/.bashrc', '/bashrc')
print 'Added /bashrc'
except IOError as e:
if e.errno == errno.EEXIST:
print 'Removing /bashrc'
hadoopy.rmr('/bashrc')
else:
raise e
But instead had to write:
try:
hadoopy.put('/root/.bashrc', '/bashrc')
print 'Added /bashrc'
except IOError as e:
if e.message.strip().endswith('File exists'):
print 'Removing /bashrc'
hadoopy.rmr('/bashrc')
else:
raise e