server/utils.py
changeset 1910 864aa3ea0db5
parent 1802 d628defebc17
child 1977 606923dff11b
equal deleted inserted replaced
1906:7c266edf28bd 1910:864aa3ea0db5
    61 
    61 
    62 
    62 
    63 DEFAULT_MSG = 'we need a manager connection on the repository \
    63 DEFAULT_MSG = 'we need a manager connection on the repository \
    64 (the server doesn\'t have to run, even should better not)'
    64 (the server doesn\'t have to run, even should better not)'
    65 
    65 
    66 def manager_userpasswd(user=None, passwd=None, msg=DEFAULT_MSG, confirm=False):
    66 def manager_userpasswd(user=None, msg=DEFAULT_MSG, confirm=False,
       
    67                        passwdmsg='password'):
    67     if not user:
    68     if not user:
    68         print msg
    69         print msg
    69         while not user:
    70         while not user:
    70             user = raw_input('login: ')
    71             user = raw_input('login: ')
    71         passwd = getpass('password: ')
       
    72         if confirm:
       
    73             while True:
       
    74                 passwd2 = getpass('confirm password: ')
       
    75                 if passwd == passwd2:
       
    76                     break
       
    77                 print 'password doesn\'t match'
       
    78                 passwd = getpass('password: ')
       
    79         user = unicode(user, sys.stdin.encoding)
    72         user = unicode(user, sys.stdin.encoding)
    80     elif not passwd:
    73     passwd = getpass('%s: ' % passwdmsg)
    81         assert not confirm
    74     if confirm:
    82         passwd = getpass('password for %s: ' % user)
    75         while True:
       
    76             passwd2 = getpass('confirm password: ')
       
    77             if passwd == passwd2:
       
    78                 break
       
    79             print 'password doesn\'t match'
       
    80             passwd = getpass('password: ')
    83     # XXX decode password using stdin encoding then encode it using appl'encoding
    81     # XXX decode password using stdin encoding then encode it using appl'encoding
    84     return user, passwd
    82     return user, passwd
    85 
    83 
    86 
    84 
    87 class LoopTask(object):
    85 class LoopTask(object):