Fix os.getlogin() problem with no tty

Catch OSError(s) from  os.getlogin() and fall back to looking at
environment variables to figure out the user's name. The OSError
is thrown where there is no tty for the python process when
os.getlogin() is called.

Fixes LP: 1221491

Change-Id: Id6634921cdf0deb77cf32a5b9101ec475946aa81
Merge "Fix os.getlogin() problem with no tty"