~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
524
524
        import pwd
525
525
        uid = os.getuid()
526
526
        w = pwd.getpwuid(uid)
527
 
        gecos = w.pw_gecos.decode(bzrlib.user_encoding)
528
 
        username = w.pw_name.decode(bzrlib.user_encoding)
 
527
 
 
528
        try:
 
529
            gecos = w.pw_gecos.decode(bzrlib.user_encoding)
 
530
            username = w.pw_name.decode(bzrlib.user_encoding)
 
531
        except UnicodeDecodeError:
 
532
            # We're using pwd, therefore we're on Unix, so /etc/passwd is ok.
 
533
            raise errors.BzrError("Can't decode username in " \
 
534
                    "/etc/passwd as %s." % bzrlib.user_encoding)
 
535
 
529
536
        comma = gecos.find(',')
530
537
        if comma == -1:
531
538
            realname = gecos
536
543
 
537
544
    except ImportError:
538
545
        import getpass
539
 
        realname = username = getpass.getuser().decode(bzrlib.user_encoding)
 
546
        try:
 
547
            realname = username = getpass.getuser().decode(bzrlib.user_encoding)
 
548
        except UnicodeDecodeError:
 
549
            raise errors.BzrError("Can't decode username as %s." % \
 
550
                    bzrlib.user_encoding)
540
551
 
541
552
    return realname, (username + '@' + socket.gethostname())
542
553