'Attempt to find the username in a cross-platform fashion.'

def _GetUsername(self):

    try:
        return (os.getenv('USER') or os.getenv('LOGNAME') or os.getenv('USERNAME') or os.getlogin() or 'nobody')
    except (AttributeError, IOError, OSError):
        return 'nobody'
