def chown(path, user, group):
 path = os.path.expanduser(path)
 uid = user_to_uid(user)
 gid = group_to_gid(group)
 err = ''
 if (uid == ''):
  if user:
   err += 'User does not exist\n'
  else:
   uid = (-1)
 if (gid == ''):
  if group:
   err += 'Group does not exist\n'
  else:
   gid = (-1)
 if (not os.path.exists(path)):
  try:
   return os.lchown(path, uid, gid)
  except OSError:
   pass
  err += 'File not found'
 if err:
  return err
 return os.chown(path, uid, gid)

def chown ( path , user , group ) : path = os . path . expanduser ( path ) uid = user_to_uid ( user ) gid = group_to_gid ( group ) err = '' if ( uid == '' ) : if user : err += 'User does not exist\n' else : uid = ( - 1 ) if ( gid == '' ) : if group : err += 'Group does not exist\n' else : gid = ( - 1 ) if ( not os . path . exists ( path ) ) : try : return os . lchown ( path , uid , gid ) except OSError : pass err += 'File not found' if err : return err return os . chown ( path , uid , gid )
changes the ownership of the given file to the given .