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

Subscribers

People subscribed via source and target branches