~gz/bzr-lpreview/dry_run_option_not_global

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Michael Hudson
  • Date: 2007-12-17 15:48:02 UTC
  • Revision ID: michael.hudson@canonical.com-20071217154802-ruyz9yh1eqc7eqof
add support for pendingreviews generation

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
 
90
90
revision %(revno)s.
91
91
 
92
 
Example URL:
93
 
Test Command:
 
92
Demo URL: http://launchpad.dev/...
 
93
Test command: ./test.py -vv -t whatever
 
94
Pre-implementation call with: someone
94
95
 
95
96
[describe the intent of the branch here].
96
97
"""
250
251
    smtp.sendmail(FROM, to, msg.as_string())
251
252
    smtp.close()
252
253
 
 
254
pr = Option("pr", help=("Display a PendingReviews block"))
 
255
 
253
256
 
254
257
class cmd_review_submit(Command):
255
258
    """Submit a review.
284
287
        Option("review-list", short_name='l', type=unicode,
285
288
               help=("The email address of the review list the review "
286
289
                     "request should be Cc:ed to.")),
 
290
        pr,
287
291
        ]
288
292
 
289
293
    def run(self, target=None, diff=None, cover=None, reviewer='',
290
294
            remember=False, dry_run=False, review_tool_url=None,
291
 
            review_list=None):
 
295
            review_list=None, pr=False):
292
296
        merge_source_branch = Branch.open('.')
293
297
 
294
298
        branch_url = merge_source_branch.get_public_branch()
347
351
        note("Sending to %s and %s from %s.", email, review_list, from_)
348
352
        mail(merge_source_branch, from_,
349
353
             email, review_list, diff, cover, short_branch_url, dry_run)
 
354
        if pr:
 
355
            print make_pending_reviews_template(merge_source_branch, cover)
350
356
 
351
357
 
352
358
class cmd_write_cover_letter(Command):
360
366
        Option("output", short_name='o', type=unicode,
361
367
               help=("Where to save the cover letter, './cover.txt' by "
362
368
               "default.")),
 
369
        pr,
363
370
        ]
364
371
 
365
 
    def run(self, output='cover.txt'):
 
372
    def run(self, output='cover.txt', pr=None):
366
373
        merge_source_branch = Branch.open('.')
367
374
        cover = make_cover_letter_template(merge_source_branch, check=False)
368
375
        open(output, 'w').write(cover)
369
 
 
 
376
        if pr:
 
377
            print make_pending_reviews_template(merge_source_branch, cover)
 
378
 
 
379
 
 
380
pending_reviews_template = '''
 
381
 * `%(url)s`
 
382
   %(summary)s%(lines)s [[BR]]
 
383
   Target release: ''%(milestone)s'' [[BR]]
 
384
   needs-review [@DATE@]
 
385
'''
 
386
 
 
387
def active_lp_milestone():
 
388
    # hacky hacky hacky!
 
389
    for line in urllib.urlopen('https://edge.launchpad.net/launchpad/+portlet-milestones'):
 
390
        if 'href' in line:
 
391
            return line.split('>')[1].split('<')[0]
 
392
 
 
393
def make_pending_reviews_template(source_branch, cover_letter):
 
394
    chop = {}
 
395
    coverlines = cover_letter.splitlines()
 
396
    lastkey = -1
 
397
    for i, line in enumerate(coverlines):
 
398
        if ':' in line:
 
399
            key, value = line.split(':', 1)
 
400
            chop[key.strip()] = value.strip()
 
401
            lastkey = i
 
402
    summary = []
 
403
    for line in coverlines[i+1:]:
 
404
        if line.strip():
 
405
            summary.append(line.strip())
 
406
            if len(summary) >= 3:
 
407
                break
 
408
    summary = ' '.join(summary)
 
409
    if summary:
 
410
        summary += ' [[BR]]\n  '
 
411
    keys = [('Demo URL', '%s'),
 
412
            ('Test command', '`%s`'),
 
413
            ('Pre-implementation call with', "''%s''")
 
414
            ]
 
415
    input, output = os.popen2(
 
416
        os.path.expanduser('~/canonical/lp-branches/trunk/utilities/paste'))
 
417
    input.write(cover_letter)
 
418
    input.close()
 
419
    cover_url = output.read().strip()
 
420
    output.close()
 
421
    lines = ['Cover letter: %s' % cover_url]
 
422
    for (k, fmt) in keys:
 
423
        if k in chop:
 
424
            lines.append('%s: %s'%(k, fmt%chop[k]))
 
425
    vals = {
 
426
        'lines': ' [[BR]]\n   '.join(lines),
 
427
        'milestone': active_lp_milestone(),
 
428
        'url': source_branch.get_public_branch(),
 
429
        'summary': summary,
 
430
        }
 
431
    return pending_reviews_template%vals
 
432
 
 
433
class cmd_pr_block(Command):
 
434
    """Create a cover letter template and prompt to fill it out.
 
435
 
 
436
    The file will be saved as 'cover.txt' in the current directory by
 
437
    default.
 
438
    """
 
439
 
 
440
    takes_options = [
 
441
        Option("cover", short_name='c', type=open,
 
442
               help=("")),
 
443
        ]
 
444
 
 
445
    def run(self, cover=None):
 
446
        merge_source_branch = Branch.open('.')
 
447
        if cover is None:
 
448
            cover = make_cover_letter_template(merge_source_branch)
 
449
        else:
 
450
            cover = cover.read()
 
451
        print make_pending_reviews_template(merge_source_branch, cover)
370
452
 
371
453
register_command(cmd_review_submit)
372
454
register_command(cmd_diff_for_review)
373
455
register_command(cmd_write_cover_letter)
 
456
register_command(cmd_pr_block)