Skip to content

Commit

Permalink
[1.2.X] Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.g…
Browse files Browse the repository at this point in the history
…etpwuid 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
  • Loading branch information
jezdez committed Nov 17, 2010
1 parent 9057450 commit 395af9d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions django/contrib/auth/management/commands/createsuperuser.py
Expand Up @@ -3,7 +3,6 @@
""" """


import getpass import getpass
import os
import re import re
import sys import sys
from optparse import make_option from optparse import make_option
Expand All @@ -30,10 +29,10 @@ class Command(BaseCommand):
make_option('--email', dest='email', default=None, make_option('--email', dest='email', default=None,
help='Specifies the email address for the superuser.'), help='Specifies the email address for the superuser.'),
make_option('--noinput', action='store_false', dest='interactive', default=True, make_option('--noinput', action='store_false', dest='interactive', default=True,
help='Tells Django to NOT prompt the user for input of any kind. ' \ help=('Tells Django to NOT prompt the user for input of any kind. '
'You must use --username and --email with --noinput, and ' \ 'You must use --username and --email with --noinput, and '
'superusers created with --noinput will not be able to log in ' \ 'superusers created with --noinput will not be able to log '
'until they\'re given a valid password.'), 'in until they\'re given a valid password.')),
) )
help = 'Used to create a superuser.' help = 'Used to create a superuser.'


Expand All @@ -58,12 +57,11 @@ def handle(self, *args, **options):


# Try to determine the current system user's username to use as a default. # Try to determine the current system user's username to use as a default.
try: try:
import pwd default_username = getpass.getuser().replace(' ', '').lower()
default_username = pwd.getpwuid(os.getuid())[0].replace(' ', '').lower()
except (ImportError, KeyError): except (ImportError, KeyError):
# KeyError will be raised by getpwuid() if there is no # KeyError will be raised by os.getpwuid() (called by getuser())
# corresponding entry in the /etc/passwd file (a very restricted # if there is no corresponding entry in the /etc/passwd file
# chroot environment, for example). # (a very restricted chroot environment, for example).
default_username = '' default_username = ''


# Determine whether the default username is taken, so we don't display # Determine whether the default username is taken, so we don't display
Expand Down

0 comments on commit 395af9d

Please sign in to comment.