/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to send_changeset.py

  • Committer: John Arbash Meinel
  • Date: 2005-06-28 22:08:30 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050628220830-aad25e5b75a60615
Merging send-changeset updates from jrydberg

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
from email.MIMEText import MIMEText
14
14
 
15
15
 
16
 
def send_changeset(to_address, from_address, subject, 
17
 
                   changeset_fp, message):
18
 
    # Create the enclosing (outer) message
 
16
def send_changeset(b, revno, to_address, message, file, diff_options):
 
17
    from bzrlib import find_branch
 
18
    from bzrlib.commands import BzrCommandError
 
19
    import gen_changeset
 
20
    import send_changeset
 
21
    import StringIO
 
22
 
 
23
    revision = b.get_revision(b.lookup_revision(revno))
 
24
    if not message:
 
25
        message = revision.message.split('\n')[0]
 
26
 
 
27
    from_address = bzrlib.osutils._get_user_id()
 
28
 
19
29
    outer = MIMEMultipart()
20
 
    outer['Subject'] = '[PATCH] ' + subject
 
30
    outer['Subject'] = '[PATCH] ' + message
21
31
    outer['To'] = to_address
22
32
    outer['From'] = from_address
23
33
 
24
 
    if message:
25
 
        msg = MIMEText(message)
26
 
        outer.attach(msg)
27
 
 
28
 
    msg = MIMEText(changeset_fp.read())
29
 
    #msg.add_header('Content-Disposition', 'attachment', filename=')
30
 
 
31
 
    outer.attach(msg)
32
 
 
33
 
    s = smtplib.SMTP()
34
 
    s.connect()
35
 
    s.sendmail(from_address, to_address, outer.as_string())
36
 
    s.close()
 
34
    # Either read the mail body from the specified file, or spawn
 
35
    # an editor and let the user type a description.
 
36
    if file:
 
37
        mail_body = open(file, "rt").read()
 
38
    else:
 
39
        info = "Changset for revision %d by %s\n" % (revno,
 
40
                                                     revision.committer)
 
41
        info += "with the following message:\n"
 
42
        for line in revision.message.split('\n'):
 
43
            info += "  " + line + "\n"
 
44
 
 
45
        mail_body = bzrlib.osutils.get_text_message(info)
 
46
        if mail_body is None:
 
47
            raise BzrCommandError("aborted")
 
48
    outer.attach(MIMEText(mail_body))
37
49
    
 
50
    changeset_fp = StringIO.StringIO()
 
51
    gen_changeset.show_changeset(b, revno,
 
52
                                 external_diff_options=diff_options,
 
53
                                 to_file=changeset_fp)
 
54
    outer.attach(MIMEText(changeset_fp.getvalue()))
 
55
 
 
56
    try:
 
57
        fp = open(os.path.join(bzrlib.osutils.config_dir(), 'smtp-host'), 'rt')
 
58
        smtpconn = smtplib.SMTP(fp.readline().strip('\n'))
 
59
    except:
 
60
        smtpconn = smtplib.SMTP()
 
61
 
 
62
    smtpconn.connect()
 
63
    smtpconn.sendmail(from_address, to_address, outer.as_string())
 
64
    smtpconn.close()