mercurial/util.py
changeset 3099 c27d1e1798a3
parent 3010 494521a3f142
child 3126 cff3c58a5766
equal deleted inserted replaced
3010:494521a3f142 3099:c27d1e1798a3
    13 """
    13 """
    14 
    14 
    15 from i18n import gettext as _
    15 from i18n import gettext as _
    16 from demandload import *
    16 from demandload import *
    17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
    17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
    18 demandload(globals(), "os threading time pwd grp")
    18 demandload(globals(), "os threading time")
    19 
    19 
    20 # used by parsedate
    20 # used by parsedate
    21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
    21 defaultdateformats = ('%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M',
    22                       '%a %b %d %H:%M:%S %Y')
    22                       '%a %b %d %H:%M:%S %Y')
    23 
    23 
   507             return getuser_fallback()
   507             return getuser_fallback()
   508     # raised if win32api not available
   508     # raised if win32api not available
   509     raise Abort(_('user name not available - set USERNAME '
   509     raise Abort(_('user name not available - set USERNAME '
   510                   'environment variable'))
   510                   'environment variable'))
   511 
   511 
   512 def username(uid=None):
       
   513     """Return the name of the user with the given uid.
       
   514 
       
   515     If uid is None, return the name of the current user."""
       
   516     try:
       
   517         # force an ImportError if there's no module pwd
       
   518         getpwuid = pwd.getpwuid
       
   519         if uid is None:
       
   520             uid = os.getuid()
       
   521         try:
       
   522             return getpwuid(uid)[0]
       
   523         except KeyError:
       
   524             return str(uid)
       
   525     except ImportError:
       
   526         return None
       
   527 
       
   528 def groupname(gid=None):
       
   529     """Return the name of the group with the given gid.
       
   530 
       
   531     If gid is None, return the name of the current group."""
       
   532     try:
       
   533         # force an ImportError if there's no module grp
       
   534         getgrgid = grp.getgrgid
       
   535         if gid is None:
       
   536             gid = os.getgid()
       
   537         try:
       
   538             return getgrgid(gid)[0]
       
   539         except KeyError:
       
   540             return str(gid)
       
   541     except ImportError:
       
   542         return None
       
   543 
       
   544 # Platform specific variants
   512 # Platform specific variants
   545 if os.name == 'nt':
   513 if os.name == 'nt':
   546     demandload(globals(), "msvcrt")
   514     demandload(globals(), "msvcrt")
   547     nulldev = 'NUL:'
   515     nulldev = 'NUL:'
   548 
   516