aboutsummaryrefslogtreecommitdiff
path: root/tools/launchpad/get-blueprints.py
blob: 545d14de33ff760c1fe9813a4a87936936f9d582 (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python2.7

import os
import sys
import re

import launchpadlib
from launchpadlib.launchpad import Launchpad

def parse_meta_item(line, filename):
    '''Parse a meta information line from a blueprint

    '''

    line = line.strip()
    if not line:
        return

    try:
        (key, value) = line.rsplit(':', 1)
        key   = key.strip()
        value = value.strip()
    except ValueError:
        #print("\tMeta line '%s' can not be parsed" % line)
        return

    print("\t\tkey='%s' value='%s'" % (key, value))
    if key == "Headline" or key == "Acceptance":
        filename.write(" %s ||" % value)

if __name__ == '__main__':
    project_name = sys.argv[1]
    milestone_name = sys.argv[2]

    CACHE_DIR = os.path.expanduser('~/.launchpadlib/cache')

    launchpad = Launchpad.login_anonymously(
                'linaro project management',
                'production',
                version='devel')

    meta_re = re.compile('^Meta.*?:$', re.I)

    filename = './blueprint-%s.moin' % project_name
    outfile = open(filename, 'w')

    matching_project = launchpad.projects[project_name]
    if matching_project is None:
        logging.error("No projects matching '%s' found." % project_name)
        sys.exit(1)

    project_blueprints = matching_project.valid_specifications
    for bp in project_blueprints:
        milestone = bp.milestone
        if milestone is not None and milestone.name == milestone_name:
            print "%s\n" % (bp.web_link)
            outfile.write("|| [[%s|%s]] || %s ||" %  (bp.web_link, bp.title, bp.priority))

            in_meta_block = False

            for l in bp.whiteboard.splitlines():
                if (not in_meta_block):
                    if meta_re.search(l):
                        in_meta_block = True
                    continue

                if in_meta_block:
                    #print("\tmeta line (raw): '%s'" % (l.strip()))
                    if not l.strip():
                        in_meta_block = False
                        continue
                    parse_meta_item(l, outfile)

            print "\n"
            outfile.write("  ||\n")

    outfile.close()