summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2010-11-17 20:30:44 +0000
committerJannis Leidel <jannis@leidel.info>2010-11-17 20:30:44 +0000
commit395af9d5cf0f68130bfd75b9bdb2c20a8c6ef51a (patch)
treebf59c3a49455b8556827e53bde23d03147bcd439
parent9057450af00e34e4e9d33fb2d76b83fcc1d47802 (diff)
[1.2.X] Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.getpwuid to determine the current system user's username in the createsuperuser management command to enable the feature on Windows. getpass.getuser automatically falls back to the previous method.
Backport from trunk (r14607). git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14608 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/auth/management/commands/createsuperuser.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py
index 87751527c8..9939e3da77 100644
--- a/django/contrib/auth/management/commands/createsuperuser.py
+++ b/django/contrib/auth/management/commands/createsuperuser.py
@@ -3,7 +3,6 @@ Management utility to create superusers.
"""
import getpass
-import os
import re
import sys
from optparse import make_option
@@ -30,10 +29,10 @@ class Command(BaseCommand):
make_option('--email', dest='email', default=None,
help='Specifies the email address for the superuser.'),
make_option('--noinput', action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind. ' \
- 'You must use --username and --email with --noinput, and ' \
- 'superusers created with --noinput will not be able to log in ' \
- 'until they\'re given a valid password.'),
+ help=('Tells Django to NOT prompt the user for input of any kind. '
+ 'You must use --username and --email with --noinput, and '
+ 'superusers created with --noinput will not be able to log '
+ 'in until they\'re given a valid password.')),
)
help = 'Used to create a superuser.'
@@ -58,12 +57,11 @@ class Command(BaseCommand):
# Try to determine the current system user's username to use as a default.
try:
- import pwd
- default_username = pwd.getpwuid(os.getuid())[0].replace(' ', '').lower()
+ default_username = getpass.getuser().replace(' ', '').lower()
except (ImportError, KeyError):
- # KeyError will be raised by getpwuid() if there is no
- # corresponding entry in the /etc/passwd file (a very restricted
- # chroot environment, for example).
+ # KeyError will be raised by os.getpwuid() (called by getuser())
+ # if there is no corresponding entry in the /etc/passwd file
+ # (a very restricted chroot environment, for example).
default_username = ''
# Determine whether the default username is taken, so we don't display