~0x44/nova/bug838466

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/tap/manhole.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
3
# See LICENSE for details.
 
4
 
 
5
 
 
6
"""
 
7
I am the support module for making a manhole server with twistd.
 
8
"""
 
9
 
 
10
from twisted.manhole import service
 
11
from twisted.spread import pb
 
12
from twisted.python import usage, util
 
13
from twisted.cred import portal, checkers
 
14
from twisted.application import strports
 
15
import os, sys
 
16
 
 
17
class Options(usage.Options):
 
18
    synopsis = "[options]"
 
19
    optParameters = [
 
20
           ["user", "u", "admin", "Name of user to allow to log in"],
 
21
           ["port", "p", str(pb.portno), "Port to listen on"],
 
22
    ]
 
23
 
 
24
    optFlags = [
 
25
        ["tracebacks", "T", "Allow tracebacks to be sent over the network"],
 
26
    ]
 
27
    zsh_actions = {"user" : "_users"}
 
28
 
 
29
    def opt_password(self, password):
 
30
        """Required.  '-' will prompt or read a password from stdin.
 
31
        """
 
32
        # If standard input is a terminal, I prompt for a password and
 
33
        # confirm it.  Otherwise, I use the first line from standard
 
34
        # input, stripping off a trailing newline if there is one.
 
35
        if password in ('', '-'):
 
36
            self['password'] = util.getPassword(confirm=1)
 
37
        else:
 
38
            self['password'] = password
 
39
    opt_w = opt_password
 
40
 
 
41
    def postOptions(self):
 
42
        if not self.has_key('password'):
 
43
            self.opt_password('-')
 
44
 
 
45
def makeService(config):
 
46
    port, user, password = config['port'], config['user'], config['password']
 
47
    p = portal.Portal(
 
48
        service.Realm(service.Service(config["tracebacks"], config.get('namespace'))),
 
49
        [checkers.InMemoryUsernamePasswordDatabaseDontUse(**{user: password})]
 
50
    )
 
51
    return strports.service(port, pb.PBServerFactory(p, config["tracebacks"]))