def chmod(target):
 assert isinstance(target, str)
 assert os.path.exists(target)
 file_mode = (stat.S_IRUSR | stat.S_IWUSR)
 folder_mode = ((stat.S_IRUSR | stat.S_IWUSR) | stat.S_IXUSR)
 remove_immutable_attribute(target)
 if os.path.isfile(target):
  os.chmod(target, file_mode)
 elif os.path.isdir(target):
  os.chmod(target, folder_mode)
  for (root, dirs, files) in os.walk(target):
   for cur_dir in dirs:
    os.chmod(os.path.join(root, cur_dir), folder_mode)
   for cur_file in files:
    os.chmod(os.path.join(root, cur_file), file_mode)
 else:
  raise ValueError('Unsupported file type: {}'.format(target))

def chmod ( target ) : assert isinstance ( target , str ) assert os . path . exists ( target ) file_mode = ( stat . S_IRUSR | stat . S_IWUSR ) folder_mode = ( ( stat . S_IRUSR | stat . S_IWUSR ) | stat . S_IXUSR ) remove_immutable_attribute ( target ) if os . path . isfile ( target ) : os . chmod ( target , file_mode ) elif os . path . isdir ( target ) : os . chmod ( target , folder_mode ) for ( root , dirs , files ) in os . walk ( target ) : for cur_dir in dirs : os . chmod ( os . path . join ( root , cur_dir ) , folder_mode ) for cur_file in files : os . chmod ( os . path . join ( root , cur_file ) , file_mode ) else : raise ValueError ( 'Unsupported file type: {}' . format ( target ) )
recursively set the chmod for files to 0600 and 0700 for folders .