Merge lp:~marcoceppi/juju-core/docs-bug-lint-tool into lp:juju-core/docs

Proposed by Marco Ceppi
Status: Merged
Approved by: Nick Veitch
Approved revision: no longer in the source branch.
Merged at revision: 185
Proposed branch: lp:~marcoceppi/juju-core/docs-bug-lint-tool
Merge into: lp:juju-core/docs
Diff against target: 79 lines (+75/-0)
1 file modified
tools/lint.py (+75/-0)
To merge this branch: bzr merge lp:~marcoceppi/juju-core/docs-bug-lint-tool
Reviewer Review Type Date Requested Status
charmers Pending
Review via email: mp+197375@code.launchpad.net

Description of the change

Create a linting tool which checks for bug links in docs and reports their status

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'tools/lint.py'
--- tools/lint.py 1970-01-01 00:00:00 +0000
+++ tools/lint.py 2013-12-02 14:11:33 +0000
@@ -0,0 +1,75 @@
1#!/usr/bin/python
2
3import os
4import re
5import sys
6import glob
7
8from launchpadlib.launchpad import Launchpad
9
10
11def color(status):
12 c = {'triaged': '\033[93m', 'new': '\033[91m', 'fix committed': '\033[92m',
13 'fix released': '\033[94m', 'esc': '\033[0m'}
14
15 return '%s%s%s' % (c[status.lower()], status, c['esc'])
16
17
18def get_bugs(doc_file):
19 links = get_bug_links(doc_file)
20 status = {}
21 for link in links:
22 status[link] = get_bug_status(link)
23
24 return status
25
26
27def get_bug_links(doc_file):
28 pattern = '(bugs\.launchpad\.net/.*/[0-9]+)'
29 bugs = []
30
31 try:
32 with open(doc_file) as f:
33 for line in f:
34 m = re.search(pattern, line)
35 if m:
36 url = m.group(1)
37 bugs.append(url.split('/')[-1])
38 except:
39 pass
40
41 return bugs
42
43
44def get_bug_status(bug_id):
45 lp = Launchpad.login_anonymously('juju-docs', 'production')
46 status = []
47 for task in lp.bugs[1223325].bug_tasks.entries:
48 status.append({task['bug_target_name']: task['status']})
49
50 return status
51
52if __name__ == '__main__':
53 # Find htmldocs
54 htmldocs = os.path.abspath(os.path.join(os.path.dirname(__file__), '..',
55 'htmldocs'))
56 bugs = {}
57 if not os.path.exists(htmldocs):
58 print 'Could not find htmldocs'
59 sys.exit(1)
60
61 docs = glob.glob(os.path.join(htmldocs, '*.html'))
62
63 if docs:
64 for doc in docs:
65 b = get_bugs(doc)
66 if b:
67 bugs[os.path.basename(doc)] = b
68 if bugs:
69 for doc, statuses in bugs.iteritems():
70 print "%s:" % doc
71 for bug_id, status_data in statuses.iteritems():
72 print " %s: http://pad.lv/%s" % (bug_id, bug_id)
73 for d in status_data:
74 for proj, status in d.iteritems():
75 print " # %s: %s" % (proj, color(status))

Subscribers

People subscribed via source and target branches