comparison mercurial/util.py @ 3013:494521a3f142

Only read .hg/hgrc files from trusted users/groups The list of trusted users and groups is specified in the [trusted] section of a hgrc; the current user is always trusted; "*" can be used to trust all users/groups. Global hgrc files are always read. On Windows (and other systems that don't have the pwd and grp modules), all .hg/hgrc files are read.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 22 Aug 2006 20:45:03 -0300
parents 3d5547845158
children c27d1e1798a3
comparison
equal deleted inserted replaced
3012:abcd6ae3cf5a 3013:494521a3f142
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") 18 demandload(globals(), "os threading time pwd grp")
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
512 # Platform specific variants 544 # Platform specific variants
513 if os.name == 'nt': 545 if os.name == 'nt':
514 demandload(globals(), "msvcrt") 546 demandload(globals(), "msvcrt")
515 nulldev = 'NUL:' 547 nulldev = 'NUL:'
516 548