[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [doctor/master] Send email notice when packages out of date



commit c9ee6cd537fdfece586be39acc18e2cd5c0c1e76
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Dec 18 11:03:22 2017 -0800

    Send email notice when packages out of date
    
    Now that the script itself works, time to turn this into a daemon that sends me
    notifications.
---
 package_versions.py | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/package_versions.py b/package_versions.py
index 11e31ff..b289562 100755
--- a/package_versions.py
+++ b/package_versions.py
@@ -13,6 +13,8 @@ import re
 import time
 import urllib2
 
+import util
+
 DEBIAN_VERSION = '<h1>Package: \S+ \(([0-9\.]+).*\)'
 FEDORA_VERSION = '<div class="package-name">([0-9\.]+).*</div>'
 ARCH_LINUX_VERSION = '<title>Arch Linux - \S+ ([0-9\.]+).*</title>'
@@ -78,6 +80,8 @@ PACKAGES = [
   ]),
 ]
 
+log = util.get_logger('package_versions')
+
 
 def gentoo_version(request):
   # Unlike other platforms gentoo lists all package versions, so we
@@ -98,12 +102,15 @@ def gentoo_version(request):
   return highest_version
 
 
-if __name__ == '__main__':
-  print(DIV)
-  print(COLUMN % ('Project', 'Platform', 'Version', 'Status'))
+def email_content():
+  lines = []
+  lines.append(DIV)
+  lines.append(COLUMN % ('Project', 'Platform', 'Version', 'Status'))
+
+  has_issue = False
 
   for project, packages in PACKAGES:
-    print(DIV)
+    lines.append(DIV)
 
     for package in packages:
       request, request_exc = None, None
@@ -127,13 +134,29 @@ if __name__ == '__main__':
 
         if not current_version:
           msg = 'unable to determine current version'
+          has_issue = True
         elif current_version == package.version:
           msg = 'up to date'
         else:
           msg = 'current version is %s but wiki has %s' % (current_version, package.version)
+          has_issue = True
       else:
         msg = 'unable to retrieve current version: %s' % request_exc
+        has_issue = True
+
+      lines.append(COLUMN % (project, package.platform, package.version, msg))
+
+  lines.append(DIV)
+  return '\n'.join(lines), has_issue
+
+
+if __name__ == '__main__':
+  content, has_issue = email_content()
 
-      print(COLUMN % (project, package.platform, package.version, msg))
+  if has_issue:
+    try:
+      util.send('Packages wiki possibly outdated', body = content, to = [util.ERROR_ADDRESS])
+    except Exception as exc:
+      log.warn("Unable to send email: %s" % exc)
 
-  print(DIV)
+  log.debug('\n' + content)

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits