Merge lp:~beuno/click-reviewers-tools/deprecate-14-10-dev1 into lp:click-reviewers-tools
- deprecate-14-10-dev1
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 203 |
Proposed branch: | lp:~beuno/click-reviewers-tools/deprecate-14-10-dev1 |
Merge into: | lp:click-reviewers-tools |
Diff against target: |
260 lines (+172/-19) 6 files modified
bin/update-frameworks (+20/-0) clickreviews/cr_lint.py (+28/-16) clickreviews/frameworks.py (+93/-0) clickreviews/tests/test_cr_lint.py (+11/-2) data/frameworks.json (+19/-0) debian/rules (+1/-1) |
To merge this branch: | bzr merge lp:~beuno/click-reviewers-tools/deprecate-14-10-dev1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jamie Strandboge (community) | Needs Fixing | ||
Ricardo Kirkner (community) | Approve | ||
Review via email: mp+224887@code.launchpad.net |
Commit message
Description of the change
This branch mostly adds 14-10-dev2 and deprecates 14-10-dev1.
Because it bothered me so much, I refactored the way we handle frameworks into a central static list which should be easy to update.
- 203. By Daniel Holbach
-
add script to update frameworks definition from branch, FRAMEWORKS_
BRANCH_ URL will have to be updated to be something with ~ubuntu-core-dev - 204. By Daniel Holbach
-
ran ./debian/
scripts/ update- frameworks - 205. By Daniel Holbach
-
make use of new data file
- 206. By Daniel Holbach
-
move update-frameworks to bin, make it not depend on bzr
- 207. By Daniel Holbach
-
move functionality into frameworks.py
- 208. By Daniel Holbach
-
- deal with urllib issues (no access to the net, etc.)
- save frameworks definition in ~/.cache
- update cache every week
- add error messages - 209. By Daniel Holbach
-
refine update logic, add local_copy parameter, which can be used for builds and tests
- 210. By Daniel Holbach
-
add missing import
- 211. By Daniel Holbach
-
rename variables to make more sense, simplify read_frameworks
_file logic somewhat, introduce a Frameworks class - 212. By Daniel Holbach
-
pass filename to get_frameworks_file
- 213. By Daniel Holbach
-
call update-frameworks in clean target
- 214. By Daniel Holbach
-
use Frameworks class
- 215. By Daniel Holbach
-
remove debian/scripts
- 216. By Daniel Holbach
-
change URL and explain that this bazaar.lp.net hack will be gone soon
- 217. By Daniel Holbach
-
move makedirs call to the right place
Ricardo Kirkner (ricardokirkner) wrote : | # |
- 218. By Martin Albisetti
-
Fixes from Daniel
Ricardo Kirkner (ricardokirkner) wrote : | # |
<dholbach> pindonga, about the two other things I guess it'd help to file general bugs, so we can fix it everywhere else as well - the unreadable variable names were probably used, since the call is basically used in every check
<pindonga> dholbach, so you're saying you're not fixing these 2 issues for consistency with the rest of the code?
<pindonga> dholbach, just so I understand the reason
<dholbach> beuno, ^ do you have an opinion on this?
<beuno> dholbach, pindonga, I'm happy to favor consistency, yes
- 219. By Martin Albisetti
-
More fixes from Daniel
Jamie Strandboge (jdstrand) wrote : | # |
I like the approach, though I have a couple of comments:
* ./run-pep8 shows some problems-- these should be fixed
* it was a little odd at first seeing all the stuff in frameworks.py about USER_DATA_FILE and cr_lint.py not using it, but then I realized that the scripts are always going to use data/frameworks
* there are no tests for frameworks.py-- not sure how feasible these are
* it would be nice if the change to test_check_
Please fix the pep8 and if you are feeling industrious, modify test_check_
Jamie Strandboge (jdstrand) : | # |
Jamie Strandboge (jdstrand) wrote : | # |
I fixed the pep8 issues and committed. Thanks!
Preview Diff
1 | === added file 'bin/update-frameworks' |
2 | --- bin/update-frameworks 1970-01-01 00:00:00 +0000 |
3 | +++ bin/update-frameworks 2014-07-02 16:33:58 +0000 |
4 | @@ -0,0 +1,20 @@ |
5 | +#!/usr/bin/python3 |
6 | + |
7 | +from clickreviews import frameworks |
8 | +import sys |
9 | + |
10 | +def main(filename=None): |
11 | + frameworks.get_frameworks_file(filename) |
12 | + |
13 | +if __name__ == '__main__': |
14 | + try: |
15 | + filename = None |
16 | + if len(sys.argv) > 2: |
17 | + print("Usage: %s [file]" % sys.argv[0]) |
18 | + sys.exit(1) |
19 | + elif len(sys.argv) == 2: |
20 | + filename = sys.argv[1] |
21 | + main(filename) |
22 | + except KeyboardInterrupt: |
23 | + print('Aborted.', file=sys.stderr) |
24 | + sys.exit(1) |
25 | |
26 | === modified file 'clickreviews/cr_lint.py' |
27 | --- clickreviews/cr_lint.py 2014-05-30 08:33:09 +0000 |
28 | +++ clickreviews/cr_lint.py 2014-07-02 16:33:58 +0000 |
29 | @@ -21,6 +21,7 @@ |
30 | import os |
31 | import re |
32 | |
33 | +from clickreviews.frameworks import Frameworks |
34 | from clickreviews.cr_common import ClickReview, open_file_read, cmd |
35 | |
36 | CONTROL_FILE_NAMES = ["control", "manifest", "md5sums", "preinst"] |
37 | @@ -529,26 +530,37 @@ |
38 | |
39 | def check_framework(self): |
40 | '''Check framework()''' |
41 | - t = 'info' |
42 | n = 'framework' |
43 | - s = 'OK' |
44 | - if self.manifest['framework'] not in self.valid_frameworks: |
45 | + l = "http://askubuntu.com/questions/460512/what-framework-should-i-use-in-my-manifest-file" |
46 | + local_copy = os.path.join(os.path.dirname(__file__), |
47 | + '../data/frameworks.json') |
48 | + frameworks = Frameworks(local_copy) |
49 | + if self.manifest['framework'] in frameworks.AVAILABLE_FRAMEWORKS: |
50 | + t = 'info' |
51 | + s = 'OK' |
52 | + self._add_result(t, n, s) |
53 | + # If it's an available framework, we're done checking |
54 | + return |
55 | + elif self.manifest['framework'] in frameworks.DEPRECATED_FRAMEWORKS: |
56 | + t = 'warn' |
57 | + s = "'%s' is deprecated. Please use a newer framework" % \ |
58 | + self.manifest['framework'] |
59 | + self._add_result(t, n, s, l) |
60 | + return |
61 | + elif self.manifest['framework'] in frameworks.OBSOLETE_FRAMEWORKS: |
62 | + t = 'error' |
63 | + s = "'%s' is obsolete. Please use a newer framework" % \ |
64 | + self.manifest['framework'] |
65 | + self._add_result(t, n, s, l) |
66 | + return |
67 | + else: |
68 | + # None of the above checks triggered, this is an unknown framework |
69 | t = 'error' |
70 | s = "'%s' is not a supported framework" % \ |
71 | self.manifest['framework'] |
72 | - self._add_result(t, n, s) |
73 | - |
74 | - deprecated_frameworks = ['ubuntu-sdk-13.10'] |
75 | - t = 'info' |
76 | - n = 'current framework' |
77 | - s = 'OK' |
78 | - l = None |
79 | - if self.manifest['framework'] in deprecated_frameworks: |
80 | - t = 'warn' |
81 | - s = "'%s' is deprecated. Please use a newer framework" % \ |
82 | - self.manifest['framework'] |
83 | - l = "http://askubuntu.com/questions/460512/what-framework-should-i-use-in-my-manifest-file" |
84 | - self._add_result(t, n, s, l) |
85 | + self._add_result(t, n, s, l) |
86 | + |
87 | + |
88 | |
89 | def check_click_local_extensions(self): |
90 | '''Report any click local extensions''' |
91 | |
92 | === added file 'clickreviews/frameworks.py' |
93 | --- clickreviews/frameworks.py 1970-01-01 00:00:00 +0000 |
94 | +++ clickreviews/frameworks.py 2014-07-02 16:33:58 +0000 |
95 | @@ -0,0 +1,93 @@ |
96 | +""" |
97 | +This file defines all known frameworks and their current status. |
98 | +Frameworks are currenly tracked in: http://goo.gl/z9ohJ3 |
99 | +""" |
100 | + |
101 | +import json |
102 | +import os |
103 | +import re |
104 | +from socket import timeout |
105 | +import sys |
106 | +import time |
107 | +from urllib import request, parse |
108 | +from urllib.error import HTTPError, URLError |
109 | + |
110 | +DATA_DIR = os.path.join(os.path.expanduser('~/.cache/ubuntu-frameworks/')) |
111 | +USER_DATA_FILE = os.path.join(DATA_DIR, 'frameworks.json') |
112 | + |
113 | +# XXX: This is a hack and will be gone, as soon as myapps has an API for this. |
114 | +FRAMEWORKS_DATA_URL = \ |
115 | + "http://bazaar.launchpad.net/~ubuntu-core-dev/+junk/frameworks/view/head:/frameworks.json" |
116 | + |
117 | +UPDATE_INTERVAL = 60*60*24*7 |
118 | + |
119 | +def update_is_necessary(): |
120 | + return (not os.path.exists(USER_DATA_FILE)) or \ |
121 | + (time.time()-os.path.getctime(USER_DATA_FILE) >= UPDATE_INTERVAL) |
122 | + |
123 | +def update_is_possible(): |
124 | + update = True |
125 | + try: |
126 | + request.urlopen(FRAMEWORKS_DATA_URL) |
127 | + except (HTTPError, URLError): |
128 | + update = False |
129 | + except timeout: |
130 | + update = False |
131 | + return update |
132 | + |
133 | +def abort(msg=None): |
134 | + if msg: |
135 | + print(msg, file=sys.stderr) |
136 | + print('Aborted.', file=sys.stderr) |
137 | + sys.exit(1) |
138 | + |
139 | +def get_frameworks_file(data_dir=DATA_DIR): |
140 | + try: |
141 | + f = request.urlopen(FRAMEWORKS_DATA_URL) |
142 | + except (HTTPError, URLError) as error: |
143 | + abort('Data not retrieved because %s.' % error) |
144 | + except timeout: |
145 | + abort('Socket timed out.') |
146 | + html = f.read() |
147 | + # XXX: This is a hack and will be gone, as soon as myapps has an API for this. |
148 | + link = re.findall(b'<a href="(\S+?)">download file</a>', html) |
149 | + if not link: |
150 | + abort() |
151 | + download_link = '{}://{}/{}'.format(\ |
152 | + parse.urlparse(FRAMEWORKS_DATA_URL).scheme, |
153 | + parse.urlparse(FRAMEWORKS_DATA_URL).netloc, |
154 | + link[0].decode("utf-8")) |
155 | + f = request.urlopen(download_link) |
156 | + if not f: |
157 | + abort() |
158 | + if os.path.exists(USER_DATA_FILE): |
159 | + os.remove(USER_DATA_FILE) |
160 | + if not os.path.exists(DATA_DIR): |
161 | + os.makedirs(DATA_DIR) |
162 | + with open(USER_DATA_FILE, 'bw') as local_file: |
163 | + local_file.write(f.read()) |
164 | + |
165 | +def read_frameworks_file(local_copy=None): |
166 | + if update_is_necessary() and update_is_possible(): |
167 | + get_frameworks_file() |
168 | + if not os.path.exists(USER_DATA_FILE): |
169 | + if local_copy: |
170 | + return json.loads(open(local_copy, 'r').read()) |
171 | + return {} |
172 | + return json.loads(open(USER_DATA_FILE, 'r').read()) |
173 | + |
174 | +class Frameworks(object): |
175 | + DEPRECATED_FRAMEWORKS = [] |
176 | + OBSOLETE_FRAMEWORKS = [] |
177 | + AVAILABLE_FRAMEWORKS = [] |
178 | + |
179 | + def __init__(self, local_copy=None): |
180 | + self.FRAMEWORKS = read_frameworks_file(local_copy) |
181 | + |
182 | + for k, v in self.FRAMEWORKS.items(): |
183 | + if v == 'deprecated': |
184 | + self.DEPRECATED_FRAMEWORKS.append(k) |
185 | + elif v == 'obsolete': |
186 | + self.OBSOLETE_FRAMEWORKS.append(k) |
187 | + elif v == 'available': |
188 | + self.AVAILABLE_FRAMEWORKS.append(k) |
189 | |
190 | === modified file 'clickreviews/tests/test_cr_lint.py' |
191 | --- clickreviews/tests/test_cr_lint.py 2014-05-30 08:33:09 +0000 |
192 | +++ clickreviews/tests/test_cr_lint.py 2014-07-02 16:33:58 +0000 |
193 | @@ -601,11 +601,11 @@ |
194 | |
195 | def test_check_framework(self): |
196 | '''Test check_framework()''' |
197 | - self.set_test_manifest("framework", "ubuntu-sdk-14.04-qml-dev1") |
198 | + self.set_test_manifest("framework", "ubuntu-sdk-14.10-qml-dev2") |
199 | c = ClickReviewLint(self.test_name) |
200 | c.check_framework() |
201 | r = c.click_report |
202 | - expected_counts = {'info': 2, 'warn': 0, 'error': 0} |
203 | + expected_counts = {'info': 1, 'warn': 0, 'error': 0} |
204 | self.check_results(r, expected_counts) |
205 | |
206 | def test_check_framework_bad(self): |
207 | @@ -626,6 +626,15 @@ |
208 | expected_counts = {'info': None, 'warn': 1, 'error': 0} |
209 | self.check_results(r, expected_counts) |
210 | |
211 | + def test_check_framework_obsolete(self): |
212 | + '''Test check_framework() - obsolete''' |
213 | + self.set_test_manifest("framework", "ubuntu-sdk-14.10-qml-dev1") |
214 | + c = ClickReviewLint(self.test_name) |
215 | + c.check_framework() |
216 | + r = c.click_report |
217 | + expected_counts = {'info': None, 'warn': 0, 'error': 1} |
218 | + self.check_results(r, expected_counts) |
219 | + |
220 | def test_check_hooks(self): |
221 | '''Test check_hooks()''' |
222 | self.set_test_manifest("framework", "ubuntu-sdk-13.10") |
223 | |
224 | === added directory 'data' |
225 | === added file 'data/frameworks.json' |
226 | --- data/frameworks.json 1970-01-01 00:00:00 +0000 |
227 | +++ data/frameworks.json 2014-07-02 16:33:58 +0000 |
228 | @@ -0,0 +1,19 @@ |
229 | +{ |
230 | + "ubuntu-sdk-13.10": "deprecated", |
231 | + "ubuntu-sdk-14.04-dev1": "deprecated", |
232 | + "ubuntu-sdk-14.04-html-dev1": "deprecated", |
233 | + "ubuntu-sdk-14.04-papi-dev1": "deprecated", |
234 | + "ubuntu-sdk-14.04-qml-dev1": "deprecated", |
235 | + "ubuntu-sdk-14.04": "available", |
236 | + "ubuntu-sdk-14.04-html": "available", |
237 | + "ubuntu-sdk-14.04-papi": "available", |
238 | + "ubuntu-sdk-14.04-qml": "available", |
239 | + "ubuntu-sdk-14.10-dev1": "obsolete", |
240 | + "ubuntu-sdk-14.10-html-dev1": "obsolete", |
241 | + "ubuntu-sdk-14.10-papi-dev1": "obsolete", |
242 | + "ubuntu-sdk-14.10-qml-dev1": "obsolete", |
243 | + "ubuntu-sdk-14.10-dev2": "available", |
244 | + "ubuntu-sdk-14.10-html-dev2": "available", |
245 | + "ubuntu-sdk-14.10-papi-dev2": "available", |
246 | + "ubuntu-sdk-14.10-qml-dev2": "available" |
247 | +} |
248 | |
249 | === modified file 'debian/rules' |
250 | --- debian/rules 2013-09-26 10:42:09 +0000 |
251 | +++ debian/rules 2014-07-02 16:33:58 +0000 |
252 | @@ -18,7 +18,7 @@ |
253 | rm -rf build *.egg-info .pybuild |
254 | find -name \*.pyc -print0 | xargs -0r rm -f |
255 | find -name __pycache__ -print0 | xargs -0r rm -rf |
256 | - |
257 | + -$(shell python3 ./bin/update-frameworks ./data) |
258 | |
259 | override_dh_auto_build: |
260 | dh_auto_build |
Looks good overall, but needs a few small tweaks