~psivaa/uci-engine/lander-jenkins-with-proxy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python

import os
import subprocess
import sys


from launchpadlib import credentials
from lazr.restfulclient import errors
sys.path.insert(0, os.path.join(os.path.dirname(__file__), './ci-utils'))
from ci_utils import dump_stack

web_root="https://launchpad.net/"

creds_path = os.path.abspath('lp_creds.txt')

def create():
    creds = credentials.Credentials('ci-airline')
    url = creds.get_request_token(web_root=web_root)

    subprocess.call(['xdg-open', url])
    sys.stderr.write("Authenticate from your browser (just opened),"
                     " choose 'Change anything'\nthen press enter\n")
    sys.stdin.readline()
    try:
        creds.exchange_request_token_for_access_token(web_root=web_root)
    except errors.HTTPError as e:
        if e.response['status'] == '403':
            sys.stderr.write('Ok, not creating credentials then\n')
            exit(1)
        raise

    with open(creds_path, 'wb') as f:
        creds.save(f)
    sys.stderr.write('Credentials created in {}\n'.format(creds_path))

    print('export CI_OAUTH_CONSUMER_KEY={}'.format(creds.consumer.key))
    print('export CI_OAUTH_TOKEN={}'.format(creds.access_token.key))
    print('export CI_OAUTH_TOKEN_SECRET={}'.format(creds.access_token.secret))
    # Can't find lp user in the creds, it's bzr lp-login anyway
    print('export CI_LAUNCHPAD_USER=`bzr lp-login`')
    # This should be a team that owns the ppa build pool
    print('export CI_LAUNCHPAD_PPA_OWNER=`bzr lp-login`')
    return 0


def main(args):
    create()


if __name__ == '__main__':
    dump_stack.install_stack_dump_signal()
    sys.exit(main(sys.argv[1:]))