~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to lp_registration.py

  • Committer: Martin Pool
  • Date: 2006-03-22 19:21:20 UTC
  • mto: (1668.1.8 bzr-0.8.mbp)
  • mto: This revision was merged to the branch mainline in revision 1710.
  • Revision ID: mbp@sourcefrog.net-20060322192120-133f1e99d4c79477
Update xmlrpc api

Prompt for user password when registering

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
from getpass import getpass
18
19
from urlparse import urlsplit, urlunsplit
19
20
from urllib import unquote, quote
20
21
import xmlrpclib
21
22
 
 
23
import bzrlib.config
22
24
 
23
25
# TODO: use last component of the branch's url as the default id?
24
26
 
38
40
    # want.  But it might be useful for testing.
39
41
 
40
42
    def __init__(self, branch_url, branch_id):
 
43
        assert branch_url
41
44
        self.branch_url = branch_url
42
 
        self.branch_id = branch_id
 
45
        if branch_id:
 
46
            self.branch_id = branch_id
 
47
        else:
 
48
            self.branch_id = self._find_default_branch_id(self.branch_url)
 
49
        self.branch_title = ''
43
50
        self.branch_description = ''
44
 
        self.owner_email = ''
 
51
        self.author_email = ''
45
52
        self.product_name = ''
46
53
        self.service_url = self.DEFAULT_SERVICE_URL
47
 
        self.registrant = 'testuser@launchpad.net'
48
 
        self.password = 'testpassword'
 
54
        self.registrant_email = 'testuser@launchpad.net'
 
55
        self.registrant_password = 'testpassword'
49
56
 
50
57
    def _request_params(self):
51
58
        """Return xmlrpc request parameters"""
53
60
        # method
54
61
        return (self.branch_url,
55
62
                self.branch_id,
 
63
                self.branch_title,
56
64
                self.branch_description,
57
 
                self.owner_email,
 
65
                self.author_email,
58
66
                self.product_name,
59
67
               )
60
68
 
71
79
        # auth info must be in url
72
80
        scheme, hostinfo, path = urlsplit(self.service_url)[:3]
73
81
        assert '@' not in hostinfo
74
 
        hostinfo = '%s:%s@%s' % (quote(self.registrant),
75
 
                                 quote(self.password),
 
82
        hostinfo = '%s:%s@%s' % (quote(self.registrant_email),
 
83
                                 quote(self.registrant_password),
76
84
                                 hostinfo)
77
85
        url = urlunsplit((scheme, hostinfo, path, '', ''))
78
86
        proxy = xmlrpclib.ServerProxy(url, transport=transport)
79
87
        proxy.register_branch(*self._request_params())
80
88
 
 
89
    def _find_default_branch_id(self, branch_url):
 
90
        i = branch_url.rfind('/')
 
91
        return branch_url[i+1:]
 
92
 
 
93
def register_interactive(branch_url):
 
94
    """Register a branch, prompting for a password if needed."""
 
95
    rego = BranchRegistrationRequest(branch_url, '')
 
96
    config = bzrlib.config.GlobalConfig()
 
97
    rego.registrant_email = config.user_email()
 
98
    prompt = 'launchpad.net password for %s: ' % \
 
99
            rego.registrant_email
 
100
    rego.registrant_password = getpass(prompt)
 
101
    rego.submit()