import os

def getUserHome():
    home = os.getenv("HOME")
    if home: return home
    try:
        import pwd
        return pwd.getpwuid(os.getuid())[5]
    except:
        pass
    return ""

def getUserName():
    s = ""
    try:
        import pwd
        s = pwd.getpwuid(os.getuid())[4]
        import re
        # At least Debian can have extra
        # information after the name in the form
        # of
        # - initial nice value
        # - initial umask
        # - initial ulimit
        # The gecos field is great...
        s = re.sub(",[^,]*,[^,]*,[^,]*", "", s)
    except:
        pass
    if not s: s = os.getenv("USER")
    if not s: s = os.getenv("LOGNAME")
    return s
