def verify_dir_has_perm(path, perm, levels=0):
 if (not os.path.exists(path)):
  raise RuntimeError(('%s does NOT exist!' % path))
 path = os.path.normpath(path)
 pdepth = len(path.split(os.path.sep))
 pathaccess = os.access(path, perm)
 if ((not levels) or (not pathaccess)):
  return pathaccess
 for (root, dirs, files) in os.walk(path):
  currentlevel = (len(root.split(os.path.sep)) - pdepth)
  if (currentlevel > levels):
   break
  elif ('.git' in dirs):
   dirs.remove('.git')
  for file_path in (os.path.join(root, f) for f in (dirs + files)):
   if os.path.exists(file_path):
    if (not os.access(file_path, perm)):
     return False
 return True

def verify_dir_has_perm ( path , perm , levels = 0 ) : if ( not os . path . exists ( path ) ) : raise RuntimeError ( ( '%s does NOT exist!' % path ) ) path = os . path . normpath ( path ) pdepth = len ( path . split ( os . path . sep ) ) pathaccess = os . access ( path , perm ) if ( ( not levels ) or ( not pathaccess ) ) : return pathaccess for ( root , dirs , files ) in os . walk ( path ) : currentlevel = ( len ( root . split ( os . path . sep ) ) - pdepth ) if ( currentlevel > levels ) : break elif ( '.git' in dirs ) : dirs . remove ( '.git' ) for file_path in ( os . path . join ( root , f ) for f in ( dirs + files ) ) : if os . path . exists ( file_path ) : if ( not os . access ( file_path , perm ) ) : return False return True
verify that home directory has perm access for current user .