~psivaa/uci-engine/lander-jenkins-plugin

« back to all changes in this revision

Viewing changes to create_private_lp_creds.py

  • Committer: Ursula Junque (Ursinha)
  • Date: 2014-05-06 22:00:52 UTC
  • mto: This revision was merged to the branch mainline in revision 412.
  • Revision ID: ursinha@canonical.com-20140506220052-3cq8846f432wlm53
Adding helper script to create private credentials

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
import subprocess
 
5
import sys
 
6
 
 
7
import launchpadlib.uris
 
8
from launchpadlib.launchpad import Launchpad
 
9
from lazr.restfulclient import errors
 
10
sys.path.insert(0, os.path.join(os.path.dirname(__file__), './ci-utils'))
 
11
from ci_utils import dump_stack
 
12
 
 
13
web_root = "https://mthoodapi.lacinonac.com/"
 
14
 
 
15
old = launchpadlib.uris.web_root_for_service_root
 
16
 
 
17
 
 
18
def web_root_for_service_root(service_root):
 
19
    if service_root == 'https://mthoodapi.lacinonac.com/':
 
20
        return 'https://mthood.lacinonac.com/'
 
21
    return old(service_root)
 
22
 
 
23
launchpadlib.uris.web_root_for_service_root = web_root_for_service_root
 
24
 
 
25
creds_path = os.path.abspath('lp_creds.txt')
 
26
 
 
27
 
 
28
def create():
 
29
    try:
 
30
        lp = Launchpad.login_with('ci-airline', consumer_name='ci-airline',
 
31
                                  service_root=web_root, version='devel')
 
32
    except errors.HTTPError as e:
 
33
        if e.response['status'] == '403':
 
34
            sys.stderr.write('Ok, not creating credentials then\n')
 
35
            exit(1)
 
36
        raise
 
37
 
 
38
    creds = lp.credentials
 
39
    creds.save_to_path(creds_path)
 
40
    sys.stderr.write('Credentials created in {}\n'.format(creds_path))
 
41
 
 
42
    print('export CI_OAUTH_CONSUMER_KEY="{}"'.format(creds.consumer.key))
 
43
    print('export CI_OAUTH_TOKEN={}'.format(creds.access_token.key))
 
44
    print('export CI_OAUTH_TOKEN_SECRET={}'.format(creds.access_token.secret))
 
45
    print('export CI_LAUNCHPAD_USER={}'.format(lp.me.name))
 
46
    # This should be a team that owns the ppa build pool
 
47
    print('export CI_LAUNCHPAD_PPA_OWNER={}'.format(lp.me.name))
 
48
    return 0
 
49
 
 
50
 
 
51
def main(args):
 
52
    create()
 
53
 
 
54
 
 
55
if __name__ == '__main__':
 
56
    dump_stack.install_stack_dump_signal()
 
57
    sys.exit(main(sys.argv[1:]))