~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/mail/codehandler.py

  • Committer: Gary Poster
  • Date: 2011-07-27 15:25:32 UTC
  • mto: This revision was merged to the branch mainline in revision 13541.
  • Revision ID: gary.poster@canonical.com-20110727152532-50akr19c7mgcj5qu
add config option for timeout value

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
__metaclass__ = type
5
5
 
6
6
 
7
7
import operator
8
 
import os
9
8
import re
10
9
 
11
10
from bzrlib.branch import Branch
24
23
from zope.interface import implements
25
24
from zope.security.interfaces import Unauthorized
26
25
 
 
26
from canonical.launchpad.interfaces.mail import (
 
27
    EmailProcessingError,
 
28
    IMailHandler,
 
29
    )
 
30
from lp.services.messages.interfaces.message import IMessageSet
 
31
from canonical.launchpad.mail.commands import (
 
32
    EmailCommand,
 
33
    EmailCommandCollection,
 
34
    )
 
35
from canonical.launchpad.mail.helpers import (
 
36
    ensure_not_weakly_authenticated,
 
37
    get_error_message,
 
38
    get_main_body,
 
39
    get_person_or_team,
 
40
    IncomingEmailError,
 
41
    parse_commands,
 
42
    )
27
43
from canonical.launchpad.mailnotification import (
28
44
    send_process_error_notification,
29
45
    )
52
68
from lp.code.interfaces.branchtarget import check_default_stacked_on
53
69
from lp.codehosting.bzrutils import is_branch_stackable
54
70
from lp.codehosting.vfs import get_lp_server
55
 
from lp.services.mail.commands import (
56
 
    EmailCommand,
57
 
    EmailCommandCollection,
58
 
    )
59
 
from lp.services.mail.helpers import (
60
 
    ensure_not_weakly_authenticated,
61
 
    get_error_message,
62
 
    get_main_body,
63
 
    get_person_or_team,
64
 
    IncomingEmailError,
65
 
    parse_commands,
66
 
    )
67
 
from lp.services.mail.interfaces import (
68
 
    EmailProcessingError,
69
 
    IMailHandler,
70
 
    )
71
71
from lp.services.mail.sendmail import simple_sendmail
72
 
from lp.services.messages.interfaces.message import IMessageSet
73
 
 
74
 
 
75
 
error_templates = os.path.join(os.path.dirname(__file__), 'errortemplates')
76
72
 
77
73
 
78
74
class BadBranchMergeProposalAddress(Exception):
215
211
            raise EmailProcessingError(
216
212
                get_error_message(
217
213
                    'user-not-reviewer.txt',
218
 
                    error_templates=error_templates,
219
214
                    command_name=self.name,
220
215
                    target=context.merge_proposal.target_branch.bzr_identity))
221
216
 
261
256
                    command_name=op_name,
262
257
                    num_arguments_expected='one or more',
263
258
                    num_arguments_got='0'))
264
 
 
 
259
    
265
260
        # Pop the first arg as the reviewer.
266
261
        reviewer = get_person_or_team(string_args.pop(0))
267
262
        if len(string_args) > 0:
301
296
        try:
302
297
            ensure_not_weakly_authenticated(
303
298
                mail, email_addr, 'not-signed-md.txt',
304
 
                'key-not-registered-md.txt', error_templates)
 
299
                'key-not-registered-md.txt')
305
300
        except IncomingEmailError, error:
306
301
            user = getUtility(ILaunchBag).user
307
302
            send_process_error_notification(
366
361
                owner=getUtility(ILaunchBag).user,
367
362
                filealias=file_alias,
368
363
                parsed_message=mail)
369
 
            merge_proposal.createCommentFromMessage(
 
364
            comment = merge_proposal.createCommentFromMessage(
370
365
                message, context.vote, context.vote_tags, mail)
371
366
 
372
367
        except IncomingEmailError, error:
620
615
        try:
621
616
            email_body_text, md = self.findMergeDirectiveAndComment(message)
622
617
        except MissingMergeDirective:
623
 
            body = get_error_message(
624
 
                'missingmergedirective.txt',
625
 
                error_templates=error_templates)
 
618
            body = get_error_message('missingmergedirective.txt')
626
619
            simple_sendmail('merge@code.launchpad.net',
627
620
                [message.get('from')],
628
621
                'Error Creating Merge Proposal', body)
636
629
                    md, submitter)
637
630
            except NonLaunchpadTarget:
638
631
                body = get_error_message('nonlaunchpadtarget.txt',
639
 
                    error_templates=error_templates,
640
632
                    target_branch=md.target_branch)
641
633
                simple_sendmail('merge@code.launchpad.net',
642
634
                    [message.get('from')],
644
636
                return
645
637
            except BranchCreationException, e:
646
638
                body = get_error_message(
647
 
                        'branch-creation-exception.txt',
648
 
                        error_templates=error_templates,
649
 
                        reason=e)
 
639
                        'branch-creation-exception.txt', reason=e)
650
640
                simple_sendmail('merge@code.launchpad.net',
651
641
                    [message.get('from')],
652
642
                    'Error Creating Merge Proposal', body)
658
648
                # necessary arguments to addLandingTarget(). So from the email
659
649
                # body we need to extract: reviewer, review type, description.
660
650
                description = None
661
 
                review_requests = []
 
651
                review_requests=[]
662
652
                email_body_text = email_body_text.strip()
663
653
                if email_body_text != '':
664
654
                    description = email_body_text
679
669
            except BranchMergeProposalExists:
680
670
                body = get_error_message(
681
671
                    'branchmergeproposal-exists.txt',
682
 
                    error_templates=error_templates,
683
672
                    source_branch=source.bzr_identity,
684
673
                    target_branch=target.bzr_identity)
685
674
                simple_sendmail('merge@code.launchpad.net',