Merge lp:~dholbach/click-reviewers-tools/1355215 into lp:click-reviewers-tools

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 225
Proposed branch: lp:~dholbach/click-reviewers-tools/1355215
Merge into: lp:click-reviewers-tools
Diff against target: 163 lines (+135/-2)
3 files modified
bin/click-review (+130/-0)
debian/changelog (+4/-1)
run-pep8 (+1/-1)
To merge this branch: bzr merge lp:~dholbach/click-reviewers-tools/1355215
Reviewer Review Type Date Requested Status
Martin Albisetti (community) Approve
Review via email: mp+231569@code.launchpad.net

Description of the change

daniel@daydream:~/bzr/click/click-reviewers-tools.1355215$ ./bin/click-review ~/fr.skimbo.skimbou_1.3_armhf.click
Errors
------
 - lint_control_click_version_up_to_date
 Click-Version is too old, has '0.3', needs '0.4' or newer
 http://askubuntu.com/questions/417366/what-does-lint-control-click-version-up-to-date-mean/417367
 - lint_package_filename_arch_match
 'armhf' != 'all' from DEBIAN/control
Warnings
--------
 - lint_framework
 'ubuntu-sdk-13.10' is deprecated. Please use a newer framework
 http://askubuntu.com/questions/460512/what-framework-should-i-use-in-my-manifest-file
 - functional_qml_application_uses_QtWebKit
 Found files that use unsupported QtWebKit (should use UbuntuWebview (Ubuntu.Components.Extras.Browser >= 0.2) or Oxide instead): debian/skimbou/usr/share/skimbou/WebViewPage.qml ,debian/skimbou/usr/share/skimbou/pages/WebViewPage.qml ,pages/WebViewPage.qml
 http://askubuntu.com/questions/417342/what-does-functional-qml-application-uses-qtwebkit-mean/417343
daniel@daydream:~/bzr/click/click-reviewers-tools.1355215$

daniel@daydream:~/bzr/click/click-reviewers-tools.1355215$ ./bin/click-review ~/bzr/apps/randomcats/com.ubuntu.developer.dholbach.randomcats_0.8_all.click
Passed!
daniel@daydream:~/bzr/click/click-reviewers-tools.1355215$

To post a comment you must log in.
224. By Daniel Holbach

split out obtaining of module names into separate function, add doc_strings

Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

Works nicely, thanks.

alan@deep-thought:/tmp/1355215⟫ bin/click-review ~/Downloads/com.ubuntu.music_1.3.586_all.click
Errors
------
 - content_hub_valid_music_source
        'source' is empty
 - security_template_valid (apparmor.json)
        (MANUAL REVIEW) 'unconfined' not allowed
Warnings
--------
 - lint_click_local_extensions
        found unofficial extensions: x-source, x-test

225. By Daniel Holbach

add another more general comment

226. By Daniel Holbach

simplify for loop somewhat

227. By Daniel Holbach

split out report into its own function and simplify it

228. By Daniel Holbach

parse arguments, add -v/--verbose option

229. By Daniel Holbach

implement --json option, fix pep8 issues

230. By Daniel Holbach

bring final report line in sync with with what click-run-checks does

231. By Daniel Holbach

move sys.exit() to main() function

232. By Daniel Holbach

merge from trunk, resolve conflicts

Revision history for this message
Martin Albisetti (beuno) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/click-review'
2--- bin/click-review 1970-01-01 00:00:00 +0000
3+++ bin/click-review 2014-08-22 13:22:57 +0000
4@@ -0,0 +1,130 @@
5+#!/usr/bin/python3
6+
7+import argparse
8+import imp
9+import inspect
10+import json
11+import pkgutil
12+import sys
13+
14+
15+def get_modules():
16+ '''
17+ Here we have a look at all the modules in the
18+ clickreviews package and filter out a few which
19+ are not relevant.
20+
21+ Basically we look at all the ones which are
22+ derived from cr_common, where we can later on
23+ instantiate a *Review* object and run the
24+ necessary checks.
25+ '''
26+
27+ all_modules = [name for _, name, _ in
28+ pkgutil.iter_modules(['clickreviews'])]
29+ narrow_down_modules = \
30+ lambda a: a.startswith('cr_') and \
31+ a not in ['cr_common', 'cr_tests', 'cr_skeleton']
32+ return list(filter(narrow_down_modules, all_modules))
33+
34+
35+def init_main_class(module_name, click_file):
36+ '''
37+ This function will find the Click*Review class in
38+ the specified module and instantiate it with the
39+ location of the .click file we want to inspect.
40+ '''
41+
42+ module = imp.load_source(module_name,
43+ 'clickreviews/%s.py' % module_name)
44+
45+ classes = inspect.getmembers(module, inspect.isclass)
46+ find_main_class = lambda a: a[0].startswith('Click') and \
47+ not a[0].endswith('Exception') and \
48+ a[1].__module__ == module_name
49+ main_class = list(filter(find_main_class, classes))
50+ init_object = getattr(module, main_class[0][0])
51+ return init_object(click_file)
52+
53+
54+def print_findings(which, kind):
55+ '''
56+ Print a summary of the issues found.
57+ '''
58+
59+ if not which:
60+ return ''
61+ print(kind)
62+ print(''.center(len(kind), '-'))
63+ for key in which.keys():
64+ print(' - %s' % key)
65+ print('\t%s' % which[key]['text'])
66+ if 'link' in which[key]:
67+ print('\t%s' % which[key]['link'])
68+
69+
70+def report(results, args):
71+ errors = {}
72+ warnings = {}
73+ info = {}
74+
75+ for module in results:
76+ for key in results[module]['error']:
77+ errors[key] = results[module]['error'][key]
78+ for key in results[module]['warn']:
79+ warnings[key] = results[module]['warn'][key]
80+ if args.verbose:
81+ for key in results[module]['info']:
82+ info[key] = results[module]['info'][key]
83+
84+ if not args.json:
85+ print_findings(errors, 'Errors')
86+ print_findings(warnings, 'Warnings')
87+ if args.verbose:
88+ print_findings(info, 'Info')
89+ if warnings or errors:
90+ print('%s: FAILED' % args.filename)
91+ else:
92+ print('%s: passed' % args.filename)
93+ else:
94+ print(json.dumps(results, sort_keys=True, indent=2,
95+ separators=(',', ': ')))
96+ if warnings or errors:
97+ return 1
98+ return 0
99+
100+
101+def main():
102+ parser = argparse.ArgumentParser()
103+ parser.add_argument('filename', type=str,
104+ help='.click file to be inspected')
105+ parser.add_argument('-v', '--verbose', help='increase output verbosity',
106+ action='store_true')
107+ parser.add_argument('--json', help='print json output',
108+ action='store_true')
109+ args = parser.parse_args()
110+ click_file = args.filename
111+
112+ # What we are doing here is basically what all the
113+ # ./bin/click-check-* scripts do as well, so for
114+ # example something like:
115+ #
116+ # review = cr_push_helper.ClickReviewPushHelper(sys.argv[1])
117+ # review.do_checks()
118+ # rc = review.do_report()
119+ #
120+ results = {}
121+ for module in get_modules():
122+ review = init_main_class(module, click_file)
123+ review.do_checks()
124+ results[module.replace('cr_', '')] = review.click_report
125+ rc = report(results, args)
126+ sys.exit(rc)
127+
128+
129+if __name__ == '__main__':
130+ try:
131+ main()
132+ except KeyboardInterrupt:
133+ print("Aborted.")
134+ sys.exit(1)
135
136=== modified file 'debian/changelog'
137--- debian/changelog 2014-08-04 16:34:50 +0000
138+++ debian/changelog 2014-08-22 13:22:57 +0000
139@@ -12,7 +12,10 @@
140 * Match scope review with actual ini file specifications. (LP: #1350427)
141 * Point to the correct scope ini path.
142
143- -- Jamie Strandboge <jamie@ubuntu.com> Wed, 30 Jul 2014 11:31:41 -0500
144+ [ Daniel Holbach ]
145+ * Add 'click-review', which just prints errors/warnings. (LP: #1355215)
146+
147+ -- Daniel Holbach <daniel.holbach@ubuntu.com> Wed, 20 Aug 2014 16:03:35 +0200
148
149 click-reviewers-tools (0.8) utopic; urgency=medium
150
151
152=== modified file 'run-pep8'
153--- run-pep8 2014-08-22 13:18:27 +0000
154+++ run-pep8 2014-08-22 13:22:57 +0000
155@@ -2,7 +2,7 @@
156 set -e
157
158 echo "= pep8 ="
159-for i in ./bin/update-* ./bin/click-check-* ./bin/click-show-files \
160+for i in ./bin/update-* ./bin/click-check-* ./bin/click-show-files ./bin/click-review \
161 ./clickreviews/*py ./clickreviews/tests/*py ; do
162 echo "Checking $i"
163 pep8 $i

Subscribers

People subscribed via source and target branches