Go back to mostly generic build file
[build-farm.git] / mail-dead-hosts.py
index 1a73974e40ae3a741d8b085ae781c63367d2b5d8..35777f59ff3f10b555875785291717e5d8dfd0a8 100755 (executable)
@@ -17,9 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-from buildfarm import (
-    BuildFarm,
-    )
+from buildfarm.sqldb import StormCachingBuildFarm
 import optparse
 import smtplib
 from email.MIMEText import MIMEText
@@ -29,13 +27,13 @@ parser = optparse.OptionParser()
 parser.add_option("--dry-run", help="Don't actually send any emails.", action="store_true")
 (opts, args) = parser.parse_args()
 
-buildfarm = BuildFarm()
-db = buildfarm.hostdb
+buildfarm = StormCachingBuildFarm(timeout=40.0)
 
-hosts = db.dead_hosts(7 * 86400)
-for host in hosts:
-    db.sent_dead_mail(host.name)
+smtp = smtplib.SMTP()
+smtp.connect()
 
+hosts = buildfarm.hostdb.dead_hosts(7 * 86400)
+for host in hosts:
     if host.last_update:
         last_update = time.strftime("%a %b %e %H:%M:%S %Y", time.gmtime(host.last_update))
     else:
@@ -69,11 +67,12 @@ The Build Farm administration team.
     msg["Subject"] ="Your build farm host %s appears dead" % host.name
     msg["From"] = "\"Samba Build Farm\" <build@samba.org>"
     msg["To"] = "\"%s\" <%s>" % host.owner
+    msg["Bcc"] = "\"Samba Build Farm\" <build@samba.org>"
 
     if opts.dry_run:
         print msg.as_string()
     else:
-        s = smtplib.SMTP()
-        s.connect()
-        s.send(msg["From"], [msg["To"]], msg.as_string())
-        s.quit()
+        smtp.sendmail(msg["From"], [msg["To"], msg["Bcc"]], msg.as_string())
+        host.dead_mail_sent()
+buildfarm.commit()
+smtp.quit()