fix windows username problem.
authorVadim Gelfer <vadim.gelfer@gmail.com>
Mon, 24 Jul 2006 09:11:26 -0700
changeset 2645 e6a41cbaa260
parent 2640 02b6fa7bbfbf
child 2646 8796d9991100
fix windows username problem.
mercurial/ui.py
mercurial/util.py
mercurial/util_win32.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -197,7 +197,7 @@ class ui(object):
             user = os.environ.get("EMAIL")
         if user is None:
             try:
-                user = '%s@%s' % (getpass.getuser(), socket.getfqdn())
+                user = '%s@%s' % (util.getuser(), socket.getfqdn())
             except KeyError:
                 raise util.Abort(_("Please specify a username."))
         return user
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -12,7 +12,7 @@ platform-specific details from the core.
 
 from i18n import gettext as _
 from demandload import *
-demandload(globals(), "cStringIO errno popen2 re shutil sys tempfile")
+demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
 demandload(globals(), "os threading time")
 
 # used by parsedate
@@ -510,6 +510,17 @@ def is_win_9x():
     except AttributeError:
         return os.name == 'nt' and 'command' in os.environ.get('comspec', '')
 
+getuser_fallback = None
+
+def getuser():
+    '''return name of current user'''
+    try:
+        return getpass.getuser()
+    except ImportError:
+        return getuser_fallback and getuser_fallback()
+    raise util.Abort(_('user name not available - set USERNAME '
+                       'environment variable'))
+
 # Platform specific variants
 if os.name == 'nt':
     demandload(globals(), "msvcrt")
--- a/mercurial/util_win32.py
+++ b/mercurial/util_win32.py
@@ -297,3 +297,5 @@ class posixfile_nt(object):
             win32file.SetEndOfFile(self.handle)
         except pywintypes.error, err:
             raise WinIOError(err)
+
+getuser_fallback = win32api.GetUserName