فهرست منبع

Ask for username and password if we're in interactive mode and we don't have one.

Chris McDonough 19 سال پیش
والد
کامیت
7773c5007a
1فایلهای تغییر یافته به همراه19 افزوده شده و 1 حذف شده
  1. 19 1
      src/supervisor/supervisorctl.py

+ 19 - 1
src/supervisor/supervisorctl.py

@@ -64,6 +64,7 @@ class Controller(cmd.Cmd):
     def onecmd(self, line):
         """ Override the onecmd method to catch and print all exceptions
         """
+        origline = line
         cmd, arg, line = self.parseline(line)
         if not line:
             return self.emptyline()
@@ -78,7 +79,24 @@ class Controller(cmd.Cmd):
             except AttributeError:
                 return self.default(line)
             try:
-                return func(arg)
+                try:
+                    return func(arg)
+                except xmlrpclib.ProtocolError, e:
+                    if e.errcode == 401:
+                        if self.options.interactive:
+                            self._output('Server requires authentication')
+                            username = raw_input('Username:')
+                            password = getpass.getpass(prompt='Password:')
+                            self._output('')
+                            self.options.username = username
+                            self.options.password = password
+                            return self.onecmd(origline)
+                        else:
+                            self.options.usage('Server requires authentication')
+                    else:
+                        raise
+            except SystemExit:
+                raise
             except Exception, e:
                 (file, fun, line), t, v, tbinfo = asyncore.compact_traceback()
                 error = 'error: %s, %s: file: %s line: %s' % (t, v, file, line)