Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #7077 and #7431 -- Use getpass.getuser instead of pwd.g…

…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...
commit 395af9d5cf0f68130bfd75b9bdb2c20a8c6ef51a 1 parent 9057450
Jannis Leidel authored November 17, 2010
18  django/contrib/auth/management/commands/createsuperuser.py
@@ -3,7 +3,6 @@
3 3
 """
4 4
 
5 5
 import getpass
6  
-import os
7 6
 import re
8 7
 import sys
9 8
 from optparse import make_option
@@ -30,10 +29,10 @@ class Command(BaseCommand):
30 29
         make_option('--email', dest='email', default=None,
31 30
             help='Specifies the email address for the superuser.'),
32 31
         make_option('--noinput', action='store_false', dest='interactive', default=True,
33  
-            help='Tells Django to NOT prompt the user for input of any kind. '    \
34  
-                 'You must use --username and --email with --noinput, and '      \
35  
-                 'superusers created with --noinput will not be able to log in '  \
36  
-                 'until they\'re given a valid password.'),
  32
+            help=('Tells Django to NOT prompt the user for input of any kind. '
  33
+                  'You must use --username and --email with --noinput, and '
  34
+                  'superusers created with --noinput will not be able to log '
  35
+                  'in until they\'re given a valid password.')),
37 36
     )
38 37
     help = 'Used to create a superuser.'
39 38
 
@@ -58,12 +57,11 @@ def handle(self, *args, **options):
58 57
 
59 58
         # Try to determine the current system user's username to use as a default.
60 59
         try:
61  
-            import pwd
62  
-            default_username = pwd.getpwuid(os.getuid())[0].replace(' ', '').lower()
  60
+            default_username = getpass.getuser().replace(' ', '').lower()
63 61
         except (ImportError, KeyError):
64  
-            # KeyError will be raised by getpwuid() if there is no
65  
-            # corresponding entry in the /etc/passwd file (a very restricted
66  
-            # chroot environment, for example).
  62
+            # KeyError will be raised by os.getpwuid() (called by getuser())
  63
+            # if there is no corresponding entry in the /etc/passwd file
  64
+            # (a very restricted chroot environment, for example).
67 65
             default_username = ''
68 66
 
69 67
         # Determine whether the default username is taken, so we don't display

0 notes on commit 395af9d

Please sign in to comment.
Something went wrong with that request. Please try again.