Merge lp:~marcoceppi/charm-tools/style-fixes into lp:~charmers/charm-tools/trunk
- style-fixes
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Mark Mims |
Approved revision: | 170 |
Merge reported by: | Mark Mims |
Merged at revision: | not available |
Proposed branch: | lp:~marcoceppi/charm-tools/style-fixes |
Merge into: | lp:~charmers/charm-tools/trunk |
Diff against target: |
1033 lines (+270/-232) 13 files modified
Makefile (+2/-0) charm (+8/-6) ez_setup.py (+51/-67) misc/bash-completion (+10/-9) scripts/create (+45/-38) scripts/getall (+8/-9) scripts/promulgate (+34/-23) scripts/review (+13/-10) scripts/review-queue (+48/-32) scripts/subscribers (+34/-23) tests/helpers/run_with_timeout.py (+4/-2) tests/mediawiki.sh (+7/-7) tests/wiki-slave.sh (+6/-6) |
To merge this branch: | bzr merge lp:~marcoceppi/charm-tools/style-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mark Mims (community) | Approve | ||
Clint Byrum (community) | Disapprove | ||
Review via email: mp+150374@code.launchpad.net |
Commit message
Description of the change
This just fixes all the files to have the same indentation and "style" of coding. Making it easier to read and switch between files.
Marco Ceppi (marcoceppi) wrote : | # |
Thanks for the feedback clint. I'll add that feedback squash and re-open the merge request when I get done formatting all the files!
- 170. By Marco Ceppi
-
Make all Python scripts follow PEP8, lint code during make check
Marco Ceppi (marcoceppi) wrote : | # |
Updated to use PEP8 formatting, implemented Clint's feedback
Kapil Thangavelu (hazmat) wrote : | # |
This merge proposal broke the unit tests, and is *NOT* in the ppa because
the packaging there runs the unit tests.
On Thu, Mar 14, 2013 at 12:19 PM, Mark Mims <email address hidden> wrote:
> The proposal to merge lp:~marcoceppi/charm-tools/style-fixes into
> lp:charm-tools has been updated.
>
> Status: Approved => Merged
>
> For more details, see:
>
> https:/
> --
>
> https:/
> Your team charmers is subscribed to branch lp:charm-tools.
>
Marco Ceppi (marcoceppi) wrote : | # |
Kapil, sorry for that it looks like there was something committed in upstream that failed the pep8 test. I've fixed that code so `make check` works properly now, see https:/
Preview Diff
1 | === modified file 'Makefile' |
2 | --- Makefile 2012-09-05 22:19:13 +0000 |
3 | +++ Makefile 2013-02-25 21:57:30 +0000 |
4 | @@ -35,3 +35,5 @@ |
5 | tests/proof/test.sh |
6 | tests/create/test.sh |
7 | PYTHONPATH=helpers/python python helpers/python/charmhelpers/tests/test_charmhelpers.py |
8 | + @echo PEP8 Lint of Python files |
9 | + pep8 ./ `grep -rl '^#!/.*python' .` |
10 | |
11 | === modified file 'charm' |
12 | --- charm 2012-08-28 18:59:42 +0000 |
13 | +++ charm 2013-02-25 21:57:30 +0000 |
14 | @@ -9,10 +9,10 @@ |
15 | |
16 | usage() |
17 | { |
18 | - echo "usage: $1 [ --help|-h ] [ script_name ]" >&2 |
19 | - echo script choices are: >&2 |
20 | - echo $(list_commands)|sed -e 's/^/ /' >&2 |
21 | - exit $2 |
22 | + echo "usage: $1 [ --help|-h ] [ script_name ]" >&2 |
23 | + echo script choices are: >&2 |
24 | + echo $(list_commands)|sed -e 's/^/ /' >&2 |
25 | + exit $2 |
26 | } |
27 | |
28 | list_commands() |
29 | @@ -40,9 +40,11 @@ |
30 | if [ -z "$script" ] ; then |
31 | usage $(basename $0) 0 |
32 | fi |
33 | + |
34 | if [ -x $script_home/$script ] ; then |
35 | - shift |
36 | - exec $script_home/$script $* |
37 | + shift |
38 | + exec $script_home/$script $* |
39 | fi |
40 | + |
41 | echo "abort: Unknown script $script" >&2 |
42 | usage $(basename $0) 2 |
43 | |
44 | === modified file 'ez_setup.py' |
45 | --- ez_setup.py 2012-03-01 23:00:50 +0000 |
46 | +++ ez_setup.py 2013-02-25 21:57:30 +0000 |
47 | @@ -19,7 +19,8 @@ |
48 | """ |
49 | import sys |
50 | DEFAULT_VERSION = "0.6c11" |
51 | -DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" % sys.version[:3] |
52 | +DEFAULT_URL = "http://pypi.python.org/packages/%s/s/setuptools/" \ |
53 | + % sys.version[:3] |
54 | |
55 | md5_data = { |
56 | 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', |
57 | @@ -66,9 +67,14 @@ |
58 | 'setuptools-0.6c9-py2.6.egg': 'ca37b1ff16fa2ede6e19383e7b59245a', |
59 | } |
60 | |
61 | -import sys, os |
62 | -try: from hashlib import md5 |
63 | -except ImportError: from md5 import md5 |
64 | +import os |
65 | +import sys |
66 | + |
67 | +try: |
68 | + from hashlib import md5 |
69 | +except ImportError: |
70 | + from md5 import md5 |
71 | + |
72 | |
73 | def _validate_md5(egg_name, data): |
74 | if egg_name in md5_data: |
75 | @@ -81,6 +87,7 @@ |
76 | sys.exit(2) |
77 | return data |
78 | |
79 | + |
80 | def use_setuptools( |
81 | version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, |
82 | download_delay=15 |
83 | @@ -96,17 +103,22 @@ |
84 | this routine will print a message to ``sys.stderr`` and raise SystemExit in |
85 | an attempt to abort the calling script. |
86 | """ |
87 | - was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules |
88 | + was_imported = 'pkg_resources' in sys.modules \ |
89 | + or 'setuptools' in sys.modules |
90 | + |
91 | def do_download(): |
92 | - egg = download_setuptools(version, download_base, to_dir, download_delay) |
93 | + egg = download_setuptools(version, download_base, to_dir, |
94 | + download_delay) |
95 | sys.path.insert(0, egg) |
96 | - import setuptools; setuptools.bootstrap_install_from = egg |
97 | + import setuptools |
98 | + setuptools.bootstrap_install_from = egg |
99 | try: |
100 | import pkg_resources |
101 | except ImportError: |
102 | return do_download() |
103 | try: |
104 | - pkg_resources.require("setuptools>="+version); return |
105 | + pkg_resources.require("setuptools>=" + version) |
106 | + return |
107 | except pkg_resources.VersionConflict, e: |
108 | if was_imported: |
109 | print >>sys.stderr, ( |
110 | @@ -122,19 +134,22 @@ |
111 | except pkg_resources.DistributionNotFound: |
112 | return do_download() |
113 | |
114 | + |
115 | def download_setuptools( |
116 | version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, |
117 | - delay = 15 |
118 | + delay=15 |
119 | ): |
120 | """Download setuptools from a specified location and return its filename |
121 | |
122 | `version` should be a valid setuptools version number that is available |
123 | as an egg for download under the `download_base` URL (which should end |
124 | with a '/'). `to_dir` is the directory where the egg will be downloaded. |
125 | - `delay` is the number of seconds to pause before an actual download attempt. |
126 | + `delay` is the number of seconds to pause before an actual download |
127 | + attempt. |
128 | """ |
129 | - import urllib2, shutil |
130 | - egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) |
131 | + import urllib2 |
132 | + import shutil |
133 | + egg_name = "setuptools-%s-py%s.egg" % (version, sys.version[:3]) |
134 | url = download_base + egg_name |
135 | saveto = os.path.join(to_dir, egg_name) |
136 | src = dst = None |
137 | @@ -157,53 +172,24 @@ |
138 | and place it in this directory before rerunning this script.) |
139 | ---------------------------------------------------------------------------""", |
140 | version, download_base, delay, url |
141 | - ); from time import sleep; sleep(delay) |
142 | + ) |
143 | + from time import sleep |
144 | + sleep(delay) |
145 | log.warn("Downloading %s", url) |
146 | src = urllib2.urlopen(url) |
147 | # Read/write all in one block, so we don't create a corrupt file |
148 | # if the download is interrupted. |
149 | data = _validate_md5(egg_name, src.read()) |
150 | - dst = open(saveto,"wb"); dst.write(data) |
151 | + dst = open(saveto, "wb") |
152 | + dst.write(data) |
153 | finally: |
154 | - if src: src.close() |
155 | - if dst: dst.close() |
156 | + if src: |
157 | + src.close() |
158 | + if dst: |
159 | + dst.close() |
160 | return os.path.realpath(saveto) |
161 | |
162 | |
163 | - |
164 | - |
165 | - |
166 | - |
167 | - |
168 | - |
169 | - |
170 | - |
171 | - |
172 | - |
173 | - |
174 | - |
175 | - |
176 | - |
177 | - |
178 | - |
179 | - |
180 | - |
181 | - |
182 | - |
183 | - |
184 | - |
185 | - |
186 | - |
187 | - |
188 | - |
189 | - |
190 | - |
191 | - |
192 | - |
193 | - |
194 | - |
195 | - |
196 | - |
197 | def main(argv, version=DEFAULT_VERSION): |
198 | """Install or upgrade setuptools and EasyInstall""" |
199 | try: |
200 | @@ -212,9 +198,9 @@ |
201 | egg = None |
202 | try: |
203 | egg = download_setuptools(version, delay=0) |
204 | - sys.path.insert(0,egg) |
205 | + sys.path.insert(0, egg) |
206 | from setuptools.command.easy_install import main |
207 | - return main(list(argv)+[egg]) # we're done here |
208 | + return main(list(argv) + [egg]) # we're done here |
209 | finally: |
210 | if egg and os.path.exists(egg): |
211 | os.unlink(egg) |
212 | @@ -226,7 +212,7 @@ |
213 | ) |
214 | sys.exit(2) |
215 | |
216 | - req = "setuptools>="+version |
217 | + req = "setuptools>=" + version |
218 | import pkg_resources |
219 | try: |
220 | pkg_resources.require(req) |
221 | @@ -235,16 +221,18 @@ |
222 | from setuptools.command.easy_install import main |
223 | except ImportError: |
224 | from easy_install import main |
225 | - main(list(argv)+[download_setuptools(delay=0)]) |
226 | - sys.exit(0) # try to force an exit |
227 | + main(list(argv) + [download_setuptools(delay=0)]) |
228 | + sys.exit(0) # try to force an exit |
229 | else: |
230 | if argv: |
231 | from setuptools.command.easy_install import main |
232 | main(argv) |
233 | else: |
234 | - print "Setuptools version",version,"or greater has been installed." |
235 | + print "Setuptools version", version, "or greater has been " \ |
236 | + + "installed." |
237 | print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' |
238 | |
239 | + |
240 | def update_md5(filenames): |
241 | """Update our built-in md5 registry""" |
242 | |
243 | @@ -252,7 +240,7 @@ |
244 | |
245 | for name in filenames: |
246 | base = os.path.basename(name) |
247 | - f = open(name,'rb') |
248 | + f = open(name, 'rb') |
249 | md5_data[base] = md5(f.read()).hexdigest() |
250 | f.close() |
251 | |
252 | @@ -262,7 +250,9 @@ |
253 | |
254 | import inspect |
255 | srcfile = inspect.getsourcefile(sys.modules[__name__]) |
256 | - f = open(srcfile, 'rb'); src = f.read(); f.close() |
257 | + f = open(srcfile, 'rb') |
258 | + src = f.read() |
259 | + f.close() |
260 | |
261 | match = re.search("\nmd5_data = {\n([^}]+)}", src) |
262 | if not match: |
263 | @@ -270,19 +260,13 @@ |
264 | sys.exit(2) |
265 | |
266 | src = src[:match.start(1)] + repl + src[match.end(1):] |
267 | - f = open(srcfile,'w') |
268 | + f = open(srcfile, 'w') |
269 | f.write(src) |
270 | f.close() |
271 | |
272 | |
273 | -if __name__=='__main__': |
274 | - if len(sys.argv)>2 and sys.argv[1]=='--md5update': |
275 | +if __name__ == '__main__': |
276 | + if len(sys.argv) > 2 and sys.argv[1] == '--md5update': |
277 | update_md5(sys.argv[2:]) |
278 | else: |
279 | main(sys.argv[1:]) |
280 | - |
281 | - |
282 | - |
283 | - |
284 | - |
285 | - |
286 | |
287 | === modified file 'misc/bash-completion' |
288 | --- misc/bash-completion 2012-05-23 21:56:10 +0000 |
289 | +++ misc/bash-completion 2013-02-25 21:57:30 +0000 |
290 | @@ -49,10 +49,11 @@ |
291 | fi |
292 | fi |
293 | |
294 | - cmdOpts=( ) |
295 | - cmdOpts=(--help) |
296 | - optEnums=( ) |
297 | - fixedWords=( ) |
298 | + cmdOpts=() |
299 | + cmdOpts=(--help) |
300 | + optEnums=() |
301 | + fixedWords=() |
302 | + |
303 | case "$cmd" in |
304 | get) |
305 | for charm in $(_charm_official_charms) ; do |
306 | @@ -66,13 +67,13 @@ |
307 | IFS=$'\n' |
308 | if [[ "$cur" == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then |
309 | # complete directly after "--option=", list all enum values |
310 | - COMPREPLY=( "${optEnums[@]}" ) |
311 | + COMPREPLY=("${optEnums[@]}") |
312 | return 0 |
313 | else |
314 | - fixedWords=( "${cmdOpts[@]}" |
315 | - "${globalOpts[@]}" |
316 | - "${optEnums[@]}" |
317 | - "${fixedWords[@]}" ) |
318 | + fixedWords=("${cmdOpts[@]}" |
319 | + "${globalOpts[@]}" |
320 | + "${optEnums[@]}" |
321 | + "${fixedWords[@]}") |
322 | fi |
323 | |
324 | if [[ ${#fixedWords[@]} -gt 0 ]]; then |
325 | |
326 | === modified file 'scripts/create' |
327 | --- scripts/create 2012-08-28 18:59:42 +0000 |
328 | +++ scripts/create 2013-02-25 21:57:30 +0000 |
329 | @@ -18,7 +18,8 @@ |
330 | # You should have received a copy of the GNU General Public License |
331 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
332 | |
333 | -import sys, os |
334 | +import os |
335 | +import sys |
336 | import os.path as path |
337 | import time |
338 | import shutil |
339 | @@ -31,15 +32,16 @@ |
340 | from Cheetah.Template import Template |
341 | from stat import ST_MODE |
342 | |
343 | + |
344 | def portable_get_maintainer(): |
345 | """ Portable best effort to determine a maintainer """ |
346 | if 'NAME' in os.environ: |
347 | name = os.environ['NAME'] |
348 | else: |
349 | - name = pwd.getpwuid( os.getuid() ).pw_gecos.split(',')[0].strip() |
350 | + name = pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip() |
351 | |
352 | if not len(name): |
353 | - username = pwd.getpwuid( os.getuid() ) [0] |
354 | + username = pwd.getpwuid(os.getuid())[0] |
355 | name = username |
356 | |
357 | email = os.environ.get('EMAIL', '%s@%s' % (name, socket.getfqdn())) |
358 | @@ -52,62 +54,67 @@ |
359 | |
360 | parser = argparse.ArgumentParser() |
361 | parser.add_argument('charmname', help='Name of charm to create.') |
362 | -parser.add_argument('charmhome', nargs='?', |
363 | +parser.add_argument('charmhome', nargs='?', |
364 | help='Dir to create charm in. Defaults to CHARM_HOME env var or PWD') |
365 | args = parser.parse_args() |
366 | |
367 | if args.charmhome: |
368 | charm_home = args.charmhome |
369 | else: |
370 | - charm_home = os.getenv('CHARM_HOME','.') |
371 | + charm_home = os.getenv('CHARM_HOME', '.') |
372 | |
373 | home = path.abspath(path.join(path.dirname(sys.argv[0]), '..')) |
374 | template_dir = path.join(home, 'templates') |
375 | output_dir = path.join(charm_home, args.charmname) |
376 | -print "Generating template for " + args.charmname + " from templates in " + template_dir |
377 | +print "Generating template for " + args.charmname + " from templates in " \ |
378 | + + template_dir |
379 | print "Charm will be stored in " + output_dir |
380 | |
381 | if path.exists(output_dir): |
382 | - print output_dir + " exists. Please move it out of the way." |
383 | - sys.exit(1) |
384 | - |
385 | -shutil.copytree(path.join(template_dir,'charm'), output_dir) |
386 | - |
387 | -v={'package': args.charmname, |
388 | - 'maintainer': '%s <%s>' % get_maintainer() } |
389 | + print output_dir + " exists. Please move it out of the way." |
390 | + sys.exit(1) |
391 | + |
392 | +shutil.copytree(path.join(template_dir, 'charm'), output_dir) |
393 | + |
394 | +v = {'package': args.charmname, |
395 | + 'maintainer': '%s <%s>' % get_maintainer()} |
396 | |
397 | try: |
398 | c = apt.Cache() |
399 | c.open() |
400 | p = c[args.charmname] |
401 | - print "Found " + args.charmname + " package in apt cache, as a result charm contents have been pre-populated based on package metadata." |
402 | + print "Found " + args.charmname + " package in apt cache, as a result " \ |
403 | + + "charm contents have been pre-populated based on package metadata." |
404 | + |
405 | v['summary'] = p.summary |
406 | - v['description'] = textwrap.fill(p.description,width=72, subsequent_indent=' ') |
407 | + v['description'] = textwrap.fill(p.description, width=72, |
408 | + subsequent_indent=' ') |
409 | except: |
410 | - print "Failed to find " + args.charmname + " in apt cache, creating an empty charm instead." |
411 | + print "Failed to find " + args.charmname + " in apt cache, creating " \ |
412 | + + "an empty charm instead." |
413 | v['summary'] = '<Fill in summary here>' |
414 | v['description'] = '<Multi-line description here>' |
415 | |
416 | for root, dirs, files in os.walk(output_dir): |
417 | - for outfile in files: |
418 | - full_outfile=path.join(root,outfile) |
419 | - mode = os.stat(full_outfile)[ST_MODE] |
420 | - try: |
421 | - t = Template(file=full_outfile,searchList=(v)) |
422 | - o = tempfile.NamedTemporaryFile(dir=root,delete=False) |
423 | - os.chmod(o.name, mode) |
424 | - o.write(str(t)) |
425 | - o.close() |
426 | - backupname = full_outfile + str(time.time()) |
427 | - os.rename(full_outfile, backupname) |
428 | - try: |
429 | - os.rename(o.name, full_outfile) |
430 | - os.unlink(backupname) |
431 | - except Exception, e: |
432 | - print "WARNING: Could not enable templated file: " + str(e) |
433 | - os.rename(backupname, full_outfile) |
434 | - raise |
435 | - except Exception, e: |
436 | - print "WARNING: could not process template for " + full_outfile + ": " + str(e) |
437 | - raise |
438 | - |
439 | + for outfile in files: |
440 | + full_outfile = path.join(root, outfile) |
441 | + mode = os.stat(full_outfile)[ST_MODE] |
442 | + try: |
443 | + t = Template(file=full_outfile, searchList=(v)) |
444 | + o = tempfile.NamedTemporaryFile(dir=root, delete=False) |
445 | + os.chmod(o.name, mode) |
446 | + o.write(str(t)) |
447 | + o.close() |
448 | + backupname = full_outfile + str(time.time()) |
449 | + os.rename(full_outfile, backupname) |
450 | + try: |
451 | + os.rename(o.name, full_outfile) |
452 | + os.unlink(backupname) |
453 | + except Exception, e: |
454 | + print "WARNING: Could not enable templated file: " + str(e) |
455 | + os.rename(backupname, full_outfile) |
456 | + raise |
457 | + except Exception, e: |
458 | + print "WARNING: could not process template for " + full_outfile \ |
459 | + + ": " + str(e) |
460 | + raise |
461 | |
462 | === modified file 'scripts/getall' |
463 | --- scripts/getall 2012-08-28 18:59:42 +0000 |
464 | +++ scripts/getall 2013-02-25 21:57:30 +0000 |
465 | @@ -1,8 +1,7 @@ |
466 | #!/bin/sh |
467 | set -e |
468 | |
469 | -usage() |
470 | -{ |
471 | +usage() { |
472 | echo "usage: getall path_to_charms" >&2 |
473 | echo "retrieves all charms from launchpad using mr and bzr" |
474 | exit $1 |
475 | @@ -21,12 +20,12 @@ |
476 | home=`readlink -f $home` |
477 | |
478 | if ! [ -d "$charm_home/.bzr" ] ; then |
479 | - echo initializing $charm_home as bzr repository |
480 | - bzr init-repo $charm_home |
481 | - $home/update $charm_home |
482 | - echo checking out all charms |
483 | - mr -c $charm_home/.mrconfig -d $charm_home --trust-all checkout |
484 | - echo "In order to update charms, run this script again." |
485 | + echo initializing $charm_home as bzr repository |
486 | + bzr init-repo $charm_home |
487 | + $home/update $charm_home |
488 | + echo checking out all charms |
489 | + mr -c $charm_home/.mrconfig -d $charm_home --trust-all checkout |
490 | + echo "In order to update charms, run this script again." |
491 | else |
492 | - mr -c $charm_home/.mrconfig -d $charm_home --trust-all update |
493 | + mr -c $charm_home/.mrconfig -d $charm_home --trust-all update |
494 | fi |
495 | |
496 | === modified file 'scripts/promulgate' |
497 | --- scripts/promulgate 2012-08-28 18:59:42 +0000 |
498 | +++ scripts/promulgate 2013-02-25 21:57:30 +0000 |
499 | @@ -66,7 +66,8 @@ |
500 | help='Increase verbosity level.') |
501 | |
502 | parser.add_option( |
503 | - '-u', '--unpromulgate', dest='unpromulgate', action='store_true', default=False, |
504 | + '-u', '--unpromulgate', dest='unpromulgate', action='store_true', |
505 | + default=False, |
506 | help='Un-promulgate this branch instead of promulgating it') |
507 | |
508 | parser.add_option( |
509 | @@ -74,12 +75,15 @@ |
510 | help='Override warnings and errors. USE WITH EXTREME CARE !!!!') |
511 | |
512 | parser.add_option( |
513 | - '-w', '--ignore-warnings', dest='ignore_warnings', action='store_true', default=False, |
514 | + '-w', '--ignore-warnings', dest='ignore_warnings', action='store_true', |
515 | + default=False, |
516 | help='Promulgate this branch even with warnings from charm proof') |
517 | |
518 | parser.add_option( |
519 | - '-o', '--owner-branch', dest='promulgate_owner_branch', action='store_true', default=False, |
520 | - help='Promulgate a branch owned by a someone/group other than ~charmers') |
521 | + '-o', '--owner-branch', dest='promulgate_owner_branch', |
522 | + action='store_true', default=False, |
523 | + help='Promulgate a branch owned by a someone/group other than ' |
524 | + + '~charmers') |
525 | |
526 | return parser.parse_args() |
527 | |
528 | @@ -103,7 +107,8 @@ |
529 | sys.exit(1) |
530 | if charm_proof == 100: |
531 | if ignore_warnings: |
532 | - logging.info("ignore-warnings enabled ... Continuing with warnings") |
533 | + logging.info("ignore-warnings enabled ... Continuing with " |
534 | + + "warnings") |
535 | elif force: |
536 | logging.info("force option enabled ... Continuing with warnings") |
537 | else: |
538 | @@ -116,14 +121,14 @@ |
539 | charm_metadata = os.path.join(charm_dir, 'metadata.yaml') |
540 | if not os.access(charm_metadata, os.R_OK): |
541 | logging.error("can't read charm metadata: %s", charm_metadata) |
542 | - |
543 | + |
544 | with open(charm_metadata) as metadata: |
545 | charm = yaml.load(metadata) |
546 | |
547 | return charm['name'] |
548 | |
549 | |
550 | -def find_branch_to_promulgate(lp,charm_dir,branch_url): |
551 | +def find_branch_to_promulgate(lp, charm_dir, branch_url): |
552 | if branch_url is None: |
553 | tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch( |
554 | charm_dir) |
555 | @@ -143,7 +148,7 @@ |
556 | return charm_branch |
557 | |
558 | |
559 | -def get_lp_charm_series(lp,series): |
560 | +def get_lp_charm_series(lp, series): |
561 | charm_distro = lp.distributions[DISTRIBUTION] |
562 | if series is None: |
563 | charm_series = charm_distro.current_series |
564 | @@ -163,30 +168,33 @@ |
565 | |
566 | |
567 | def update_branch_info(charm_branch, branch_status, branch_reviewer): |
568 | - logging.info( "Setting status of %s to %s", charm_branch.bzr_identity, branch_status) |
569 | + logging.info("Setting status of %s to %s", charm_branch.bzr_identity, |
570 | + branch_status) |
571 | charm_branch.lifecycle_status = branch_status |
572 | |
573 | - logging.info( "Setting reviewer of %s to %s", charm_branch.bzr_identity, branch_reviewer) |
574 | + logging.info("Setting reviewer of %s to %s", charm_branch.bzr_identity, |
575 | + branch_reviewer) |
576 | charm_branch.reviewer = branch_reviewer |
577 | |
578 | charm_branch.lp_save() |
579 | |
580 | |
581 | -def update_official_charm_branch(lp,series,charm_branch,charm_name): |
582 | - charm_series = get_lp_charm_series(lp,series) |
583 | +def update_official_charm_branch(lp, series, charm_branch, charm_name): |
584 | + charm_series = get_lp_charm_series(lp, series) |
585 | lp_charm = charm_series.getSourcePackage(name=charm_name) |
586 | if charm_branch: |
587 | - logging.info( 'Setting %s as the official branch for %s', |
588 | + logging.info('Setting %s as the official branch for %s', |
589 | charm_branch.bzr_identity, |
590 | lp_charm.name) |
591 | - update_branch_info(charm_branch, OFFICIAL_BRANCH_STATUS, lp.people[REVIEW_TEAM_NAME]) |
592 | + update_branch_info(charm_branch, OFFICIAL_BRANCH_STATUS, |
593 | + lp.people[REVIEW_TEAM_NAME]) |
594 | else: |
595 | logging.info('Removing official branch for %s', lp_charm.name) |
596 | lp_charm.setBranch(branch=charm_branch, pocket=OFFICIAL_BRANCH_POCKET) |
597 | |
598 | |
599 | def branch_owner(bzr_branch): |
600 | - lp_url = bzr_branch.bzr_identity #TODO this really sucks... better way? |
601 | + lp_url = bzr_branch.bzr_identity # TODO this really sucks... better way? |
602 | return lp_url.lstrip('lp:').split('/')[0] |
603 | |
604 | |
605 | @@ -198,7 +206,8 @@ |
606 | |
607 | def main(argv): |
608 | options, args = parse_options() |
609 | - logging.basicConfig(level=log_level(options.verbose), format='%(levelname)s:%(message)s') |
610 | + logging.basicConfig(level=log_level(options.verbose), |
611 | + format='%(levelname)s:%(message)s') |
612 | |
613 | if len(args): |
614 | charm_dir = args[0] |
615 | @@ -212,23 +221,25 @@ |
616 | |
617 | if options.unpromulgate: |
618 | logging.info('unpromulgating...') |
619 | - charm_branch = None # makes LP delete the source package. |
620 | + charm_branch = None # makes LP delete the source package. |
621 | else: |
622 | logging.info('promulgating...') |
623 | - charm_branch = find_branch_to_promulgate(lp,charm_dir,options.branch) |
624 | + charm_branch = find_branch_to_promulgate(lp, charm_dir, options.branch) |
625 | |
626 | if not is_valid_owner(charm_branch, options.promulgate_owner_branch): |
627 | logging.error(" Invalid branch owner: %s", branch_owner(charm_branch)) |
628 | - logging.error(" Branch push location must be owned by '~charmers'\n" + |
629 | - " use `bzr push --remember lp:~charmers/charms/<series>/<charm-name>/trunk`\n" + |
630 | - " or override this behavior using the '--owner-branch' option") |
631 | + logging.error(" Branch push location must be owned by '~charmers'\n" |
632 | + + " use `bzr push --remember lp:~charmers/charms/" |
633 | + + "<series>/<charm-name>/trunk`\n or override this " |
634 | + + "behavior using the '--owner-branch'" |
635 | + + " option") |
636 | return 1 |
637 | |
638 | - update_official_charm_branch(lp, options.series, charm_branch, charm_name_from_metadata(charm_dir)) |
639 | + update_official_charm_branch(lp, options.series, charm_branch, |
640 | + charm_name_from_metadata(charm_dir)) |
641 | |
642 | return 0 |
643 | |
644 | |
645 | if __name__ == '__main__': |
646 | sys.exit(main(sys.argv)) |
647 | - |
648 | |
649 | === modified file 'scripts/review' |
650 | --- scripts/review 2012-07-02 04:18:07 +0000 |
651 | +++ scripts/review 2013-02-25 21:57:30 +0000 |
652 | @@ -26,12 +26,13 @@ |
653 | from launchpadlib.launchpad import Launchpad |
654 | |
655 | |
656 | - |
657 | def parse_options(): |
658 | parser = argparse.ArgumentParser( |
659 | - description="Review a charm by adding a comment to the corresponding charm bug. The review comment can be passed as a --message arg or via stdin") |
660 | + description="Review a charm by adding a comment to the corresponding" |
661 | + + " charm bug. The review comment can be passed as a --message" |
662 | + + " arg or via stdin") |
663 | |
664 | - parser.add_argument('bug_id', |
665 | + parser.add_argument('bug_id', |
666 | help='The launchpad bug for the charm being reviewed.') |
667 | |
668 | parser.add_argument( |
669 | @@ -64,7 +65,7 @@ |
670 | def get_message_from_stdin(): |
671 | stream = sys.stdin |
672 | text = stream.read() |
673 | - sys.stdin = open('/dev/tty') # 'reset' stdin to prompt if necessary |
674 | + sys.stdin = open('/dev/tty') # 'reset' stdin to prompt if necessary |
675 | return text |
676 | |
677 | |
678 | @@ -73,19 +74,21 @@ |
679 | return message |
680 | else: |
681 | return get_message_from_stdin() |
682 | - |
683 | + |
684 | |
685 | def prompt_to_continue(bug_id): |
686 | logging.debug("prompting") |
687 | - ans = raw_input("Really add this comment to launchpad bug #%s? y/[n] " % bug_id) |
688 | + ans = raw_input("Really add this comment to launchpad bug #%s? y/[n] " |
689 | + % bug_id) |
690 | return ans.strip().lower().startswith('y') |
691 | |
692 | |
693 | def main(argv): |
694 | args = parse_options() |
695 | - logging.basicConfig(level=log_level(args.verbose), format='%(levelname)s:%(message)s') |
696 | + logging.basicConfig(level=log_level(args.verbose), |
697 | + format='%(levelname)s:%(message)s') |
698 | |
699 | - review_message = get_message(args.message) # before connecting to lp |
700 | + review_message = get_message(args.message) # before connecting to lp |
701 | |
702 | logging.debug('login with %s launchpad:', args.lp_instance) |
703 | lp = Launchpad.login_with('charm-pilot', args.lp_instance) |
704 | @@ -99,7 +102,8 @@ |
705 | |
706 | if args.skip_prompt or prompt_to_continue(bug_id): |
707 | logging.debug('adding comment') |
708 | - bug.newMessage(content=review_message) #TODO check return or catch exception |
709 | + # TODO check return or catch exception |
710 | + bug.newMessage(content=review_message) |
711 | else: |
712 | logging.debug('not adding comment') |
713 | |
714 | @@ -112,4 +116,3 @@ |
715 | |
716 | if __name__ == '__main__': |
717 | sys.exit(main(sys.argv)) |
718 | - |
719 | |
720 | === modified file 'scripts/review-queue' |
721 | --- scripts/review-queue 2012-05-23 20:42:33 +0000 |
722 | +++ scripts/review-queue 2013-02-25 21:57:30 +0000 |
723 | @@ -6,7 +6,8 @@ |
724 | import itertools |
725 | import argparse |
726 | |
727 | -def calculate_age(from_date = None): |
728 | + |
729 | +def calculate_age(from_date=None): |
730 | if not from_date: |
731 | return None |
732 | |
733 | @@ -74,68 +75,83 @@ |
734 | |
735 | def charm_review_queue(): |
736 | print "Connecting to launchpad..." |
737 | - lp = Launchpad.login_anonymously('charm-tools', 'production', version='devel', launchpadlib_dir='~/.cache/launchpadlib') |
738 | + lp = Launchpad.login_anonymously('charm-tools', 'production', |
739 | + version='devel', launchpadlib_dir='~/.cache/launchpadlib') |
740 | charm = lp.distributions['charms'] |
741 | charmers = lp.people['charmers'] |
742 | charm_contributors = lp.people['charm-contributors'] |
743 | - |
744 | + |
745 | print "Querying launchpad for bugs ..." |
746 | - bugs = charm.searchTasks(tags=['new-formula', 'new-charm'], tags_combinator="Any", status=['New', 'Confirmed', 'Triaged', 'In Progress', 'Fix Committed']) |
747 | - charmers_bugs = charmers.searchTasks(status=['New', 'Confirmed', 'Triaged', 'In Progress', 'Fix Committed']) |
748 | - |
749 | + bugs = charm.searchTasks(tags=['new-formula', 'new-charm'], |
750 | + status=['New', 'Confirmed', 'Triaged', 'In Progress', |
751 | + 'Fix Committed'], |
752 | + tags_combinator="Any") |
753 | + charmers_bugs = charmers.searchTasks( |
754 | + status=['New', 'Confirmed', 'Triaged', 'In Progress', |
755 | + 'Fix Committed']) |
756 | + |
757 | print "Querying launchpad for proposals ..." |
758 | proposals = charmers.getRequestedReviews(status="Needs review") |
759 | - charm_contributors_proposals = charm_contributors.getRequestedReviews(status="Needs review") |
760 | - |
761 | + charm_contributors_proposals = charm_contributors.getRequestedReviews( |
762 | + status="Needs review") |
763 | + |
764 | print "Building review_queue ..." |
765 | queue = list() |
766 | max_summary_length = 50 |
767 | - |
768 | + |
769 | # Bugs in charms distribution and charmers group |
770 | - for bug in itertools.chain( bugs.entries, charmers_bugs.entries ): |
771 | + for bug in itertools.chain(bugs.entries, charmers_bugs.entries): |
772 | entry_summary = bug['title'].split('"')[1].strip() |
773 | - entry_age = datetime.datetime.utcnow() - datetime.datetime.strptime(bug['date_created'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") |
774 | + bug_created = datetime.datetime.strptime( |
775 | + bug['date_created'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") |
776 | + entry_age = datetime.datetime.utcnow() - bug_created |
777 | entry = { |
778 | - 'date_created' : bug['date_created'].split("T")[0], |
779 | - 'age' : str(entry_age).split('.')[0], |
780 | - 'summary' : (entry_summary[:max_summary_length] + '...') if len(entry_summary) > max_summary_length else entry_summary, |
781 | - 'item' : bug['web_link'], |
782 | - 'status' : bug['status'], |
783 | + 'date_created': bug['date_created'].split("T")[0], |
784 | + 'age': str(entry_age).split('.')[0], |
785 | + 'summary': (entry_summary[:max_summary_length] + '...') |
786 | + if len(entry_summary) > max_summary_length else entry_summary, |
787 | + 'item': bug['web_link'], |
788 | + 'status': bug['status'], |
789 | } |
790 | queue.append(entry) |
791 | - |
792 | + |
793 | # Merge proposals in charmers group |
794 | - for proposal in itertools.chain(proposals.entries, charm_contributors_proposals.entries): |
795 | + for proposal in itertools.chain(proposals.entries, |
796 | + charm_contributors_proposals.entries): |
797 | proposal_summary = proposal['description'] |
798 | - proposal_age = datetime.datetime.utcnow() - datetime.datetime.strptime(proposal['date_created'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") |
799 | + proposal_date_created = datetime.datetime.strptime( |
800 | + proposal['date_created'].split('+')[0], "%Y-%m-%dT%H:%M:%S.%f") |
801 | + proposal_age = datetime.datetime.utcnow() - proposal_date_created |
802 | if proposal_summary is None: |
803 | proposal_summary = "Proposal" |
804 | entry = { |
805 | - 'date_created' : proposal['date_created'].split("T")[0], |
806 | - 'age' : str(proposal_age).split('.')[0], |
807 | - 'summary' : (proposal_summary[:max_summary_length] + '...') if len(proposal_summary) > max_summary_length else proposal_summary, |
808 | - 'item' : proposal['web_link'], |
809 | - 'status' : proposal['queue_status'], |
810 | + 'date_created': proposal['date_created'].split("T")[0], |
811 | + 'age': str(proposal_age).split('.')[0], |
812 | + 'summary': (proposal_summary[:max_summary_length] + '...') |
813 | + if len(proposal_summary) > max_summary_length |
814 | + else proposal_summary, |
815 | + 'item': proposal['web_link'], |
816 | + 'status': proposal['queue_status'], |
817 | } |
818 | queue.append(entry) |
819 | |
820 | return(sorted(queue, key=lambda k: k['date_created'])) |
821 | |
822 | + |
823 | def main(): |
824 | parser = argparse.ArgumentParser( |
825 | description="Shows items needing the attention of ~charmers") |
826 | parser.parse_args() |
827 | review_queue = charm_review_queue() |
828 | - keys = ['date_created', 'age', 'summary', 'item', 'status' ] |
829 | + keys = ['date_created', 'age', 'summary', 'item', 'status'] |
830 | headers = ['Date Created', 'Age', 'Summary', 'Item', 'Status'] |
831 | print "Queue length: %d" % len(review_queue) |
832 | - if type(review_queue) == type([]) and len(review_queue) > 0: |
833 | - print format_as_table(review_queue, |
834 | - keys, |
835 | - header = headers, |
836 | - sort_by_key = 'date_created', |
837 | - sort_order_reverse = False) |
838 | - |
839 | + if isinstance(review_queue, list) and len(review_queue) > 0: |
840 | + print format_as_table(review_queue, |
841 | + keys, |
842 | + header=headers, |
843 | + sort_by_key='date_created', |
844 | + sort_order_reverse=False) |
845 | |
846 | if __name__ == "__main__": |
847 | main() |
848 | |
849 | === modified file 'scripts/subscribers' |
850 | --- scripts/subscribers 2012-08-01 04:06:41 +0000 |
851 | +++ scripts/subscribers 2013-02-25 21:57:30 +0000 |
852 | @@ -28,31 +28,35 @@ |
853 | from launchpadlib import launchpad |
854 | |
855 | parser = argparse.ArgumentParser( |
856 | - description="""Prints out a report and optionally corrects found |
857 | - instances where maintainers of charms are not subscribed to bugs |
858 | - on their charm in launchpad. |
859 | - |
860 | - Users will need all charms they are interested in checking locally |
861 | - in the specified repository so that metadata.yaml can be inspected |
862 | - to find the maintainer.""") |
863 | + description="""Prints out a report and optionally corrects found |
864 | + instances where maintainers of charms are not subscribed to bugs |
865 | + on their charm in launchpad. |
866 | + |
867 | + Users will need all charms they are interested in checking locally |
868 | + in the specified repository so that metadata.yaml can be inspected |
869 | + to find the maintainer.""") |
870 | parser.add_argument('--subscribed', default=False, action='store_true', |
871 | - help='Show maintainers who are properly subscribed instead of unsubscribed') |
872 | + help='Show maintainers who are properly subscribed instead of ' |
873 | + + 'unsubscribed') |
874 | parser.add_argument('--repository', default=None, type=str, |
875 | - help='Repository to look for charms in. Defaults to $JUJU_REPOSITORY or getcwd') |
876 | + help='Repository to look for charms in. Defaults to $JUJU_REPOSITORY ' |
877 | + + 'or getcwd') |
878 | parser.add_argument('--quiet', default=False, action='store_true', |
879 | - help='Hide everything except maintainer subscription lists.') |
880 | + help='Hide everything except maintainer subscription lists.') |
881 | parser.add_argument('--series', '-s', default=None, |
882 | - help='Which series of the charm store to run against. Defaults to current dev focus') |
883 | + help='Which series of the charm store to run against. Defaults to ' |
884 | + + 'current dev focus') |
885 | parser.add_argument('--maintainer', default=None, |
886 | - help='Limit output to this maintainer\'s charms only.') |
887 | + help='Limit output to this maintainer\'s charms only.') |
888 | parser.add_argument('--log-priority', default='WARNING') |
889 | parser.add_argument('--launchpad-instance', default='production') |
890 | parser.add_argument('--fix-unsubscribed', default=False, action='store_true', |
891 | - help='Add a bug subscription for any unsubscribed maintainers. Requires --maintainer') |
892 | + help='Add a bug subscription for any unsubscribed maintainers. Requires ' |
893 | + + '--maintainer') |
894 | parser.add_argument('--force-fix-all', default=False, action='store_true', |
895 | - help=argparse.SUPPRESS) |
896 | + help=argparse.SUPPRESS) |
897 | parser.add_argument('charms', default=[], nargs='*', |
898 | - help='Charms to check for subscriptions') |
899 | + help='Charms to check for subscriptions') |
900 | |
901 | args = parser.parse_args() |
902 | |
903 | @@ -74,13 +78,15 @@ |
904 | else: |
905 | log_prio = logging.DEBUG |
906 | |
907 | -logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=log_prio) |
908 | +logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', |
909 | + level=log_prio) |
910 | |
911 | if args.quiet: |
912 | logging.disable(logging.WARNING) |
913 | |
914 | if args.maintainer is None and args.fix_unsubscribed: |
915 | - warn('Running --fix-unsubscribed and without --maintainer is against policy.') |
916 | + warn('Running --fix-unsubscribed and without --maintainer is against' |
917 | + + ' policy.') |
918 | if not args.force_fix_all: |
919 | warn('Use --force-fix-all to override policy') |
920 | sys.exit(1) |
921 | @@ -125,10 +131,12 @@ |
922 | |
923 | for charm_name in charms: |
924 | try: |
925 | - with open('%s/%s/%s/metadata.yaml' % (repository, current_series, charm_name)) as mdata: |
926 | + with open('%s/%s/%s/metadata.yaml' % (repository, current_series, |
927 | + charm_name)) as mdata: |
928 | mdata_parsed = yaml.safe_load(mdata) |
929 | except IOError: |
930 | - warn('%s/%s has no metadata in charm repo' % (current_series, charm_name)) |
931 | + warn('%s/%s has no metadata in charm repo' % (current_series, |
932 | + charm_name)) |
933 | continue |
934 | try: |
935 | maintainers = mdata_parsed['maintainer'] |
936 | @@ -141,11 +149,13 @@ |
937 | |
938 | if args.maintainer is not None: |
939 | if args.maintainer not in maintainers: |
940 | - maints_by_email = [ m.split('<')[1].split('>')[0] for m in maintainers ] |
941 | + maints_by_email = [m.split('<')[1].split('>')[0] |
942 | + for m in maintainers] |
943 | if args.maintainer not in maints_by_email: |
944 | - debug('%s not in maintainer list %s' % (args.maintainer, maintainers)) |
945 | + debug('%s not in maintainer list %s' % (args.maintainer, |
946 | + maintainers)) |
947 | continue |
948 | - |
949 | + |
950 | for maintainer in maintainers: |
951 | maint_email = maintainer.split('<')[1].split('>')[0] |
952 | lp_maintainer = lp.people.getByEmail(email=maint_email) |
953 | @@ -167,5 +177,6 @@ |
954 | else: |
955 | print msg |
956 | if args.fix_unsubscribed: |
957 | - info('adding bug subscription to %s for %s' % (charm_name, maint_email)) |
958 | + info('adding bug subscription to %s for %s' % (charm_name, |
959 | + maint_email)) |
960 | pkg.addBugSubscription(subscriber=lp_maintainer) |
961 | |
962 | === modified file 'tests/helpers/run_with_timeout.py' |
963 | --- tests/helpers/run_with_timeout.py 2012-03-12 13:06:08 +0000 |
964 | +++ tests/helpers/run_with_timeout.py 2013-02-25 21:57:30 +0000 |
965 | @@ -1,6 +1,8 @@ |
966 | #!/usr/bin/python |
967 | |
968 | -import signal,os,sys |
969 | +import os |
970 | +import sys |
971 | +import signal |
972 | |
973 | signal.alarm(60) |
974 | -os.execv(sys.argv[1],sys.argv[1:]) |
975 | +os.execv(sys.argv[1], sys.argv[1:]) |
976 | |
977 | === modified file 'tests/mediawiki.sh' |
978 | --- tests/mediawiki.sh 2012-03-12 13:06:08 +0000 |
979 | +++ tests/mediawiki.sh 2013-02-25 21:57:30 +0000 |
980 | @@ -2,18 +2,18 @@ |
981 | set -e |
982 | repository=$1 |
983 | if [ -z "$repository" ] ; then |
984 | - echo "usage: $0 path/to/repository|teardown" |
985 | - exit 1 |
986 | + echo "usage: $0 path/to/repository|teardown" |
987 | + exit 1 |
988 | fi |
989 | |
990 | JUJU=`which juju` |
991 | |
992 | if [ "$repository" = "teardown" ] ; then |
993 | - $JUJU destroy-service wiki-db || echo could not teardown wiki-db |
994 | - $JUJU destroy-service demo-wiki || echo could not teardown demo-wiki |
995 | - $JUJU destroy-service wiki-cache || echo could not teardown wiki-cache |
996 | - $JUJU destroy-service wiki-balancer || echo could not teardown wiki-balancer |
997 | - exit 0 |
998 | + $JUJU destroy-service wiki-db || echo could not teardown wiki-db |
999 | + $JUJU destroy-service demo-wiki || echo could not teardown demo-wiki |
1000 | + $JUJU destroy-service wiki-cache || echo could not teardown wiki-cache |
1001 | + $JUJU destroy-service wiki-balancer || echo could not teardown wiki-balancer |
1002 | + exit 0 |
1003 | fi |
1004 | |
1005 | $JUJU deploy --repository=$repository local:mysql wiki-db |
1006 | |
1007 | === modified file 'tests/wiki-slave.sh' |
1008 | --- tests/wiki-slave.sh 2012-03-12 13:06:08 +0000 |
1009 | +++ tests/wiki-slave.sh 2013-02-25 21:57:30 +0000 |
1010 | @@ -2,17 +2,17 @@ |
1011 | set -e |
1012 | repository=$1 |
1013 | if [ -z "$repository" ] ; then |
1014 | - echo "usage: $0 path/to/repository | teardown" |
1015 | - exit 1 |
1016 | + echo "usage: $0 path/to/repository | teardown" |
1017 | + exit 1 |
1018 | fi |
1019 | |
1020 | JUJU=`which juju` |
1021 | |
1022 | if [ "$repository" = "teardown" ] ; then |
1023 | - $JUJU destroy-service master |
1024 | - $JUJU destroy-service slave |
1025 | - $JUJU destroy-service demowiki |
1026 | - exit 0 |
1027 | + $JUJU destroy-service master |
1028 | + $JUJU destroy-service slave |
1029 | + $JUJU destroy-service demowiki |
1030 | + exit 0 |
1031 | fi |
1032 | |
1033 | $JUJU deploy --repository=$repository local:mysql master |
Hey Marco, thanks for caring! Seriously, this needs to be done.
-1 because if you're going to do an indent level, do 4 spaces, not 2. I also would suggest doing a full PEP8 style push for all the python files, since that is the de-facto standard for python formatting. Should then include that in 'make check'. If you're going to do a style change, do it *all* in one commit, as these thing are really disruptive to things like trying to do a 'bzr annotate' on a file. Then don't let it regress so you never have to do another style change again.