Commit b7b75d69 authored by Daniel Klaffenbach's avatar Daniel Klaffenbach 🐍

ldap_createsuperuser: Use input() for asking username

This should improve Python3 compatibility
parent 23a7cb65
Pipeline #13056 failed with stage
in 11 seconds
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import getpass import getpass
import sys
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
...@@ -23,8 +22,7 @@ class Command(BaseCommand): ...@@ -23,8 +22,7 @@ class Command(BaseCommand):
username = options.get('username') username = options.get('username')
if not username: if not username:
current_user = getpass.getuser() current_user = getpass.getuser()
sys.stdout.write('Username [%s]: ' %current_user) input_user = input('Username [{}]: '.format(current_user))
input_user = sys.stdin.readline().strip()
if not input_user: if not input_user:
username = current_user username = current_user
else: else:
...@@ -46,3 +44,4 @@ class Command(BaseCommand): ...@@ -46,3 +44,4 @@ class Command(BaseCommand):
else: else:
obj.save() obj.save()
self.stdout.write("Granted %s privileges to user %s." % (privilege, username)) self.stdout.write("Granted %s privileges to user %s." % (privilege, username))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment