[MERGE] openid fix getuser on windows

bzr revid: al@openerp.com-20121227164831-wc19ei95d5257d1x
This commit is contained in:
Antony Lesuisse 2012-12-27 17:48:31 +01:00
commit fc8ba82578
1 changed files with 12 additions and 1 deletions

View File

@ -46,7 +46,18 @@ oidutil.log = _logger.debug
def get_system_user():
"""Return system user info string, such as USERNAME-EUID"""
info = getpass.getuser()
try:
info = getpass.getuser()
except ImportError:
if os.name == 'nt':
# when there is no 'USERNAME' in environment, getpass.getuser()
# fail when trying to import 'pwd' module - which is unix only.
# In that case we have to fallback to real win32 API.
import win32api
info = win32api.GetUserName()
else:
raise
euid = getattr(os, 'geteuid', None) # Non available on some platforms
if euid is not None:
info = '%s-%d' % (info, euid())