summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Jehannet <julien.jehannet@logilab.fr>2009-11-09 12:23:39 +0100
committerJulien Jehannet <julien.jehannet@logilab.fr>2009-11-09 12:23:39 +0100
commit6505d63fb9e53b28ff54b60954f63a9840959905 (patch)
tree335511c70d200d732ef387dffc6088f42ef7903f
parent78d91a5ffcf12ab811aca95e3596be842b02f988 (diff)
downloadlogilab-common-6505d63fb9e53b28ff54b60954f63a9840959905.tar.gz
[C] shellutils: make getlogin() available as shellutils
-rw-r--r--shellutils.py15
-rw-r--r--test/unittest_db.py11
2 files changed, 15 insertions, 11 deletions
diff --git a/shellutils.py b/shellutils.py
index 23a1723..4a6d3c3 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]
+
+
+
diff --git a/test/unittest_db.py b/test/unittest_db.py
index 0f818ec..af288ff 100644
--- a/test/unittest_db.py
+++ b/test/unittest_db.py
@@ -1,12 +1,10 @@
"""
unit tests for module logilab.common.db
"""
-
-import os
-import pwd
import socket
from logilab.common.testlib import TestCase, unittest_main
+from logilab.common.shellutils import getlogin
from logilab.common.db import *
from logilab.common.db import PREFERED_DRIVERS
from logilab.common.adbh import (_GenericAdvFuncHelper, _SqliteAdvFuncHelper,
@@ -15,13 +13,6 @@ from logilab.common.adbh import (_GenericAdvFuncHelper, _SqliteAdvFuncHelper,
auto_register_function)
-def getlogin():
- """avoid usinng os.getlogin() because of strange tty / stdin problems
- (man 3 getlogin)
- Another solution would be to use $LOGNAME, $USER or $USERNAME
- """
- return pwd.getpwuid(os.getuid())[0]
-
class PreferedDriverTC(TestCase):
def setUp(self):
self.drivers = {"pg":[('foo', None), ('bar', None)]}