aurweb/support/scripts/newpackage-notify
Dan McGee 7c91c59245 Remove Dummy Package concept
Instead, we just store dependencies directly in the PackageDepends
table. Since we don't use this info anywhere besides the package details
page, there is little value in precalculating what is in the AUR vs.
what is not.

An upgrade path is provided via several SQL statements in the UPGRADING
document. There should be no user-visible change from this, but the DB
schema gets a bit more sane and we no longer have loads of junk packages
in our tables that are never shown to the end user. This should also
help the MySQL query planner in several cases as we no longer have to be
careful to exclude dummy packages on every query.

Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
2011-04-03 22:59:32 +02:00

100 lines
2.6 KiB
Python
Executable file

#!/usr/bin/python2 -O
# This program is intended to be run as a once-a-day cronjob, it
# sends a batched email containing the names of all new pacakges in
# the AUR, added within the last 24 hours, to those who have requested
# it on their account page.
import sys
import os
import MySQLdb, MySQLdb.connections
import ConfigParser
from time import time
# Some options
SENDMAIL = "/usr/sbin/sendmail"
SITE = "aur.archlinux.org"
FROM = "aur-notify@archlinux.org"
REPLYTO = "nobody@archlinux.org"
# Deal with configuration.
conffile = 'tupkgs.conf'
if not os.path.isfile(conffile):
print "Error: cannot access config file (%s)" % conffile
sys.exit(1)
config = ConfigParser.ConfigParser()
config.read(conffile)
# Step 1. Figure out the unix time 24 hours ago.
starttime = time() - 24 * 60 * 60
# Step 2. Do all the mysql mucking.
dbconnection = MySQLdb.connect(host=config.get('mysql', 'host'),
user=config.get('mysql', 'username'),
passwd=config.get('mysql', 'password'),
db=config.get('mysql', 'db'))
q = dbconnection.cursor()
q.execute("SELECT Packages.Name, Packages.Version, Packages.ID, "
"Packages.Description, Users.Username FROM Packages, Users "
"WHERE SubmittedTS >= %d AND "
"Packages.SubmitterUID = Users.ID" % starttime)
packages = q.fetchall()
q.execute("SELECT Users.Email FROM Users WHERE Users.NewPkgNotify = 1")
emails = q.fetchall()
# Step 3. Generate the message, depending on what we found.
# Generate the headers to say where it is going.
message = "To: \nBcc: "
emails_list=[]
for i in emails:
emails_list.append(i[0])
message = message + (", ".join(emails_list))
# E-mail headers
message = ("%s\nReply-to: %s\n"
"From: %s\nX-Mailer: Python\n"
"X-MimeOLE: Produced by %s\n" %
(message, REPLYTO, FROM, SITE))
# The subject
message = message + "Subject: AUR New Package Notification\n\n"
# TODO: Translations of message wouldn't kill anyone, but this would then need
# to find out the users language pref too.
# Ok now the body
message = "%sPackages added to %s in the last 24 hours:\n\n" % (message, SITE)
pkgs_list=[]
for i in packages:
message = ("%s%s %s\n\thttp://aur.archlinux.org/packages.php?ID=%d"
"\n\t%s\n\tSubmitted by: %s\n\n") % (
message, i[0], i[1], i[2], i[3], i[4])
message = '''%s
---
You received this email because you chose to receive new package
notifications on your user options page in the AUR. If you no
longer wish to receive this daily mailing, please go to your
user options page at http://%s and
uncheck "New Package Notify".
''' % (message, SITE)
# Print message for debug.
#print message
#sys.exit(0)
# Step 4. Mail that sucker.
mailer = os.popen("%s -t" % SENDMAIL, 'w')
mailer.write(message)
mailer.close()