def clear_dir(dirname):
    '''Deletes all files in the directory tree and then dirs'''
    for root, dirs, files in os.walk(dirname):
        for i in files:
            tmpname = os.path.join(root,i)
            logging.info('Deleting file: ' + tmpname)
            try:
                fix_read_only(tmpname)
                os.remove(tmpname)
            except Exception as e:
                logging.exception(e)
    for root, dirs, files in os.walk(dirname):
        for j in dirs:
            tmpname = os.path.join(root,j)
            logging.info('Deleting dir: ' + tmpname)
            try:
                fix_read_only(tmpname)
                os.rmdir(tmpname)
            except Exception as e:
                logging.exception(e)
    try:
        fix_read_only(dirname) 
        logging.info('Deleting dir:' + dirname)
        os.rmdir(dirname)
    except Exception as e:
        logging.exception(e)
Deletes all files in the directory tree and then dirs
recipes/Python/576903_Subversion_Directory_Removal/recipe-576903.py