diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2012-05-17 01:04:54 -0700 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2012-05-17 01:04:54 -0700 |
commit | 91c04a12e0d66dacaee81acc8c03e47afe4aafd9 (patch) | |
tree | cdbfb6c0d4dc88e135110a2701186c89c0642987 /git | |
parent | 95878d20f264eb10d09796e595e9a1d811e92e84 (diff) | |
parent | f362d10fa24395c21b1629923ccd705ba73ae996 (diff) | |
download | gitpython-91c04a12e0d66dacaee81acc8c03e47afe4aafd9.tar.gz |
Merge pull request #43 from swallat/master
Fixed 'Inappropriate ioctl for device' problem on posix systems
Without an active login shell on linux or osx, we now use the password database to obtain the active login, instead of relying on environment variables).
Diffstat (limited to 'git')
-rw-r--r-- | git/util.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/git/util.py b/git/util.py index 0e7e4cba..79c6008f 100644 --- a/git/util.py +++ b/git/util.py @@ -20,7 +20,9 @@ from smmap import ( SlidingWindowMapManager, SlidingWindowMapBuffer ) - +# Import the user database on unix based systems +if os.name == "posix": + import pwd __all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", @@ -144,12 +146,17 @@ class _RandomAccessStringIO(object): def get_user_id(): """:return: string identifying the currently active system user as name@node - :note: user can be set with the 'USER' environment variable, usually set on windows""" - ukn = 'UNKNOWN' - username = os.environ.get('USER', os.environ.get('USERNAME', ukn)) - if username == ukn and hasattr(os, 'getlogin'): - username = os.getlogin() - # END get username from login + :note: user can be set with the 'USER' environment variable, usually set on windows + :note: on unix based systems you can use the password database + to get the login name of the effective process user""" + if os.name == "posix": + username = pwd.getpwuid(os.geteuid()).pw_name + else: + ukn = 'UNKNOWN' + username = os.environ.get('USER', os.environ.get('USERNAME', ukn)) + if username == ukn and hasattr(os, 'getlogin'): + username = os.getlogin() + # END get username from login return "%s@%s" % (username, platform.node()) def is_git_dir(d): |