#!/usr/bin/python -tt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # based on fedora-rpmchecksig # Copyright (C) 2004 Adrian Reber # $Id: fedora-package-announce,v 1.1 2004/07/17 22:39:25 adrian Exp $ import rpm import re import os import os.path import sys import time import getopt import smtplib def returnHdr(ts, package): """hand back the hdr - duh - if the pkg is foobar handback None""" try: fdno = os.open(package, os.O_RDONLY) except OSError, e: hdr = None return hdr ts.setVSFlags(~(rpm.RPMVSF_NOMD5|rpm.RPMVSF_NEEDPAYLOAD)) try: hdr = ts.hdrFromFdno(fdno) except rpm.error, e: hdr = None if type(hdr) != rpm.hdr: hdr = None ts.setVSFlags(0) os.close(fdno) return hdr name = "fedora-package-announce" version = 0.1 changelog_entries = 5 new = 0 default_mail = "fedora-package-announce@fedora.us" mail_it = 0 from_addr = os.getenv('USER') + "@" + os.getenv('HOSTNAME') def usage(): print >> sys.stderr, """Usage: %s [options] [file] Options: -c the number of changelog entries to display defaults to %d -n, --new it is a new package -u, --update it is an updated package this is the default -m, --mail do not just print the announcement on the command-line but mail it to %s -t, --to email address of the receiver defaults to %s -f, --from email address of the sender defaults to %s -h, --help this help screen Argument: file the package to announce """ % (name,changelog_entries,default_mail,default_mail,from_addr) print >> sys.stderr, """%s Release %s - Copyright (C) 2004 Adrian Reber %s comes with ABSOLUTELY NO WARRANTY - for details read the license. """ % (name, version, name) try: o, a = getopt.getopt(sys.argv[1:], 'c:nuhmt:f:',['help','mail','new','update','to=','from=']) opts = {} except: usage() sys.exit(0) for k,v in o: opts[k] = v if (opts.has_key("-h") or opts.has_key("--help")): usage() sys.exit(0) if (opts.has_key("-c")): changelog_entries=eval(opts[k]) if (opts.has_key("-n") or opts.has_key("--new")): new=1 if (opts.has_key("-u") or opts.has_key("--update")): new=0 if (opts.has_key("-m") or opts.has_key("--mail")): mail_it = 1 if len(a) < 1: usage() sys.exit(0) else: package=a[0] ts = rpm.TransactionSet() ts.setVSFlags(0) hdr = returnHdr(ts, package) if hdr == None: print '%s: Could not read header' % package else: subject = "Subject:" if ( new == 1): subject += " New: " else: subject += " Update: " subject += hdr.sprintf('%{name}') + " " subject += hdr.sprintf('%{version}') main = "Name : " main += hdr.sprintf('%{name}') main += "\n" main += "Version : " main += hdr.sprintf('%{version}') main += "\n" main += "Release : " main += hdr.sprintf('%{release}') main += "\n" main += "License : " main += hdr.sprintf('%{license}') main += "\n" main += "Url : " main += hdr.sprintf('%{url}') main += "\n" main += "Summary : " main += hdr.sprintf('%{summary}') main += "\n" main += "\n" main += hdr.sprintf('%{description}') main += "\n" main += "\n" changelogname = hdr['changelogname'] changelogtext = hdr['changelogtext'] changelogtime = hdr['changelogtime'] length = len(changelogname) counter = 1 for x in range(len(changelogtext)): main += "* %s %s" % (time.strftime("%a, %d %b %Y",time.gmtime(changelogtime[x])),changelogname[x]) main += "\n" main += changelogtext[x] main += "\n" main += "\n" counter += 1 if ( counter > changelog_entries): break if (mail_it == 0): print subject main += "\n" print main else: msg = "To: " + default_mail + "\n" msg += "From: " + from_addr + "\n" msg += "User-Agent: %s/%s\n" % (name,version) msg += "X-Unexpected: The Spanish Inquisition\n" msg += "Date: " + time.strftime("%a, %d %b %Y %H:%M:%S +0000",time.gmtime()) + "\n" msg += subject + "\n\n" msg += main server = smtplib.SMTP('localhost') server.sendmail(from_addr, default_mail, msg) server.quit()