Revision 257f4c0a lib/utils.py

b/lib/utils.py
825 825
  return [i for i in os.listdir(path) if not i.startswith(".")]
826 826

  
827 827

  
828
def GetHomeDir(uid, default=None):
829
  """Try to get the homedir of the given user id.
828
def GetHomeDir(user, default=None):
829
  """Try to get the homedir of the given user.
830

  
831
  The user can be passed either as a string (denoting the name) or as
832
  an integer (denoting the user id). If the user is not found, the
833
  'default' argument is returned, which defaults to None.
830 834

  
831 835
  """
832 836
  try:
833
    result = pwd.getpwuid(uid)
837
    if isinstance(user, basestring):
838
      result = pwd.getpwnam(user)
839
    elif isinstance(user, (int, long)):
840
      result = pwd.getpwuid(user)
841
    else:
842
      raise errors.ProgrammerError("Invalid type passed to GetHomeDir (%s)" %
843
                                   type(user))
834 844
  except KeyError:
835 845
    return default
836 846
  return result.pw_dir

Also available in: Unified diff