diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2009-11-23 14:45:11 +0100 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2009-11-23 14:45:11 +0100 |
commit | 57b10e1b76dd3bd3c834bacd338076de6e35cabe (patch) | |
tree | 3f59f0a76e5bcb0bd760b37edac7b2fe906a2473 /shellutils.py | |
parent | b7e84e3fc5418641041f95a80f08fe053c004c27 (diff) | |
parent | 1b4d12cbd2ab6e6e586743df592648faa42fa26e (diff) | |
download | logilab-common-57b10e1b76dd3bd3c834bacd338076de6e35cabe.tar.gz |
Diffstat (limited to 'shellutils.py')
-rw-r--r-- | shellutils.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/shellutils.py b/shellutils.py index b9f6253..ed5d23f 100644 --- a/shellutils.py +++ b/shellutils.py @@ -42,7 +42,7 @@ def chown(path, login=None, group=None): try: uid = int(login) except ValueError: - import pwd + import pwd # Platforms: Unix uid = pwd.getpwnam(login).pw_uid if group is None: gid = -1 @@ -285,6 +285,7 @@ def confirm(question, default_is_yes=True): """ask for confirmation and return true on positive answer""" return RawInput().confirm(question, default_is_yes) + class RawInput(object): def __init__(self, input=None, printer=None): @@ -331,3 +332,15 @@ class RawInput(object): return answer == 'y' ASK = RawInput() + + +def getlogin(): + """avoid using os.getlogin() because of strange tty / stdin problems + (man 3 getlogin) + Another solution would be to use $LOGNAME, $USER or $USERNAME + """ + import pwd # Platforms: Unix + return pwd.getpwuid(os.getuid())[0] + + + |