summaryrefslogtreecommitdiff
path: root/shellutils.py
diff options
context:
space:
mode:
Diffstat (limited to 'shellutils.py')
-rw-r--r--shellutils.py15
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]
+
+
+