From: Barry A. W. <bw...@us...> - 2004-03-12 23:06:42
|
Update of /cvsroot/cvs-syncmail/CVSROOT In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10080 Modified Files: syncmail Log Message: Might as well eat our own freshest dogfood. Index: syncmail =================================================================== RCS file: /cvsroot/cvs-syncmail/CVSROOT/syncmail,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- syncmail 23 Jan 2004 15:46:46 -0000 1.23 +++ syncmail 12 Mar 2004 22:58:00 -0000 1.24 @@ -1,11 +1,11 @@ #! /usr/bin/python -# Copyright (c) 2002, 2003, Barry Warsaw, Fred Drake, and contributors +# Copyright (c) 2002, 2003, 2004 Barry Warsaw, Fred Drake, and contributors # All rights reserved. # See the accompanying LICENSE file for details. -# Compatibility: Python 2.2.3, tied to the version of Python on SourceForge's -# authenticated CVS server. +# NOTE: SourceForge currently runs Python 2.2.3, so we need to remain +# compatible with the Python 2.2 line. """Complicated notification for CVS checkins. @@ -88,37 +88,19 @@ email-addrs At least one email address. """ -__version__ = '1.2' +__version__ = '$Revision$' import os -import sys import re +import pwd +import sys import time -import string import getopt -import smtplib -import pwd import socket - -try: - from socket import getfqdn -except ImportError: - def getfqdn(): - # Python 1.5.2 :( - hostname = socket.gethostname() - byaddr = socket.gethostbyaddr(socket.gethostbyname(hostname)) - aliases = byaddr[1] - aliases.insert(0, byaddr[0]) - aliases.insert(0, hostname) - for fqdn in aliases: - if '.' in fqdn: - break - else: - fqdn = 'localhost.localdomain' - return fqdn - +import smtplib from cStringIO import StringIO +from email.Utils import formataddr # Which SMTP server to do we connect to? MAILHOST = 'localhost' @@ -159,13 +141,13 @@ if oldrev is None and newrev is None: return NOVERSION % file - if string.find(file, "'") <> -1: + if file.find("'") <> -1: # Those crazy users put single-quotes in their file names! Now we # have to escape everything that is meaningful inside double-quotes. - filestr = string.replace(file, '\\', '\\\\') - filestr = string.replace(filestr, '`', '\`') - filestr = string.replace(filestr, '"', '\"') - filestr = string.replace(filestr, '$', '\$') + filestr = filestr.replace('\\', '\\\\') + filestr = filestr.replace('`', '\`') + filestr = filestr.replace('"', '\"') + filestr = filestr.replace('$', '\$') # and quote it with double-quotes. filestr = '"' + filestr + '"' else: @@ -184,8 +166,8 @@ # Is this a binary file? Let's look at the first few # lines to figure it out: for line in lines[:5]: - for c in string.rstrip(line): - if c in string.whitespace: + for c in line.rstrip(): + if c.isspace(): continue if c < ' ' or c > chr(127): lines = BINARY_EXPLANATION_LINES[:] @@ -215,7 +197,7 @@ del lines[DIFF_HEAD_LINES:-DIFF_TAIL_LINES] lines.insert(DIFF_HEAD_LINES, '[...%d lines suppressed...]\n' % removedlines) - return string.join(lines, '') + return ''.join(lines) @@ -223,7 +205,7 @@ def quotename(name): if name and rfc822_specials_re.search(name): - return '"%s"' % string.replace(name, '"', '\\"') + return '"%s"' % name.replace('"', '\\"') else: return name @@ -239,39 +221,35 @@ # Create the smtp connection to the localhost conn = smtplib.SMTP() conn.connect(MAILHOST, MAILPORT) - user = pwd.getpwuid(os.getuid())[0] - name = string.split(pwd.getpwuid(os.getuid())[4], ',')[0] - domain = fromhost or getfqdn() + pwinfo = pwd.getpwuid(os.getuid()) + user = pwinfo[0] + name = pwinfo[4] + domain = fromhost or socket.getfqdn() address = '%s@%s' % (user, domain) s = StringIO() - sys.stdout = s datestamp = time.strftime('%a, %d %b %Y %H:%M:%S +0000', time.gmtime(time.time())) - try: - vars = {'address' : address, - 'name' : quotename(name), - 'people' : string.join(people, COMMASPACE), - 'subject' : subject, - 'version' : __version__, - 'date' : datestamp, - } - print '''\ -From: %(name)s <%(address)s> + vars = {'author' : formataddr((name, address)), + 'people' : COMMASPACE.join(people), + 'subject' : subject, + 'version' : __version__, + 'date' : datestamp, + } + print >> s, '''\ +From: %(author)s To: %(people)s''' % vars - if replyto: - print 'Reply-To: %s' % replyto - print '''\ + if replyto: + print >> s, 'Reply-To: %s' % replyto + print >>s, '''\ Subject: %(subject)s Date: %(date)s X-Mailer: Python syncmail %(version)s <http://sf.net/projects/cvs-syncmail> ''' % vars - s.write(sys.stdin.read()) - # append the diffs if available - print - for entry in entries: - print calculate_diff(entry, contextlines) - finally: - sys.stdout = sys.__stdout__ + s.write(sys.stdin.read()) + # append the diffs if available + print >> s + for entry in entries: + print >> s, calculate_diff(entry, contextlines) resp = conn.sendmail(address, people, s.getvalue()) conn.close() os._exit(0) @@ -288,8 +266,8 @@ self.tagdate = tagdate def get_entry(prefix, mapping, line, filename): - line = string.strip(line) - parts = string.split(line, "/") + line = line.strip() + parts = line.split("/") _, name, revision, timestamp, options, tagdate = parts key = namekey(prefix, name) try: @@ -297,8 +275,8 @@ except KeyError: if revision == "0": revision = None - if string.find(timestamp, "+") != -1: - timestamp, conflict = tuple(string.split(timestamp, "+")) + if timestamp.find("+") != -1: + timestamp, conflict = tuple(timestamp.split("+")) else: conflict = None entry = CVSEntry(key, revision, timestamp, conflict, @@ -324,13 +302,13 @@ line = f.readline() if not line: break -## if string.strip(line) == "D": +## if line.strip() == "D": ## continue # we could recurse down subdirs, except the Entries.Log files # we need haven't been written to the subdirs yet, so it # doesn't do us any good ## if line[0] == "D": -## name = string.split(line, "/")[1] +## name = line.split("/")[1] ## dirname = namekey(prefix, name) ## if os.path.isdir(dirname): ## m = load_change_info(dirname) @@ -350,7 +328,7 @@ # really old version of CVS break entry = get_entry(prefix, mapping, line[2:], entries_log_fn) - parts = string.split(line, "/")[1:] + parts = line.split("/")[1:] if line[0] == "A": # adding a file entry.new_revision = parts[1] @@ -368,7 +346,7 @@ tag_fn = os.path.join("CVS", "Tag") if os.path.isfile(tag_fn): f = open(tag_fn) - line = string.strip(f.readline()) + line = f.readline().strip() f.close() if line[:1] == "T": return line[1:] @@ -423,10 +401,8 @@ # $CVSROOT, followed by the list of files that are changing. if not args: usage(1, 'No CVS module specified') - changes = load_change_info() - branch = load_branch_name() subject = subject_prefix + args[0] - specs = string.split(args[0]) + specs = args[0].split() del args[0] # The remaining args should be the email addresses @@ -440,12 +416,11 @@ print 'Not sending email for imported sources.' return + branch = load_branch_name() + changes = load_change_info() + if verbose: -## print 'Python version', sys.version -## os.system("type python1.6; type python2;" -## " type python2.0; type python2.1; type python2.2;" -## " type rcsdiff; type rlog") - print 'Mailing %s...' % string.join(people, COMMASPACE) + print 'Mailing %s...' % COMMASPACE.join(people) print 'Generating notification message...' blast_mail(subject, people, changes.values(), contextlines, fromhost, replyto) |