[tor-commits] [doctor/master] Move TEST_RUN to util

atagar at torproject.org atagar at torproject.org
Sat Feb 20 20:42:16 UTC 2016


commit 63eb5d36b8ee5f4b23d879482e1214e60c58e65a
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Feb 18 08:08:19 2016 -0800

    Move TEST_RUN to util
    
    To test locally without spamming lists we have a simple TEST_RUN flag that
    prints results rather than emailing. Moving this into the util so all our
    scripts can take advantage of this.
---
 consensus_health_checker.py   | 29 +++++++++--------------------
 descriptor_checker.py         |  2 +-
 fingerprint_change_checker.py |  2 +-
 sybil_checker.py              |  2 +-
 util.py                       |  9 +++++++++
 5 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/consensus_health_checker.py b/consensus_health_checker.py
index 1962d10..e8de5bf 100755
--- a/consensus_health_checker.py
+++ b/consensus_health_checker.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright 2013, Damian Johnson and The Tor Project
+# Copyright 2013-2016, Damian Johnson and The Tor Project
 # See LICENSE for licensing information
 
 """
@@ -23,10 +23,6 @@ import stem.util.enum
 from stem import Flag
 from stem.util.lru_cache import lru_cache
 
-# Set this flag to print results rather than email them.
-
-TEST_RUN = False
-
 Runlevel = stem.util.enum.UppercaseEnum('NOTICE', 'WARNING', 'ERROR')
 
 DIRECTORY_AUTHORITIES = stem.descriptor.remote.get_authorities()
@@ -276,19 +272,16 @@ def main():
 
     log.debug('Sending notification for issues (%s)' % ', '.join(destination_labels))
 
-    if TEST_RUN:
-      print('\n'.join(map(str, issues)))
-    else:
-      body = '\n'.join(map(str, issues))
-      cc = [d.address for d in destinations.values() if d and not d.bcc]
-      bcc = [d.address for d in destinations.values() if d and d.bcc]
+    body = '\n'.join(map(str, issues))
+    cc = [d.address for d in destinations.values() if d and not d.bcc]
+    bcc = [d.address for d in destinations.values() if d and d.bcc]
 
-      util.send(EMAIL_SUBJECT, body = body, cc = cc, bcc = bcc)
+    util.send(EMAIL_SUBJECT, body = body, cc = cc, bcc = bcc)
 
-      # notification for #tor-bots
+    # notification for #tor-bots
 
-      body = '\n'.join(['[consensus-health] %s' % issue for issue in issues])
-      util.send('Announce or', body = body, to = ['tor-misc at commit.noreply.org'])
+    body = '\n'.join(['[consensus-health] %s' % issue for issue in issues])
+    util.send('Announce or', body = body, to = ['tor-misc at commit.noreply.org'])
   else:
     if issues:
       log.info("All %i issues were suppressed. Not sending a notification." % len(issues))
@@ -795,8 +788,4 @@ if __name__ == '__main__':
   except:
     msg = "consensus_health_checker.py failed with:\n\n%s" % traceback.format_exc()
     log.error(msg)
-
-    if TEST_RUN:
-      print("Error: %s" % msg)
-    else:
-      util.send("Script Error", body = msg, to = [util.ERROR_ADDRESS])
+    util.send("Script Error", body = msg, to = [util.ERROR_ADDRESS])
diff --git a/descriptor_checker.py b/descriptor_checker.py
index 05a6513..953def1 100755
--- a/descriptor_checker.py
+++ b/descriptor_checker.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright 2013, Damian Johnson and The Tor Project
+# Copyright 2013-2016, Damian Johnson and The Tor Project
 # See LICENSE for licensing information
 
 """
diff --git a/fingerprint_change_checker.py b/fingerprint_change_checker.py
index c6a4b98..493f51c 100755
--- a/fingerprint_change_checker.py
+++ b/fingerprint_change_checker.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright 2015, Damian Johnson and The Tor Project
+# Copyright 2015-2016, Damian Johnson and The Tor Project
 # See LICENSE for licensing information
 
 """
diff --git a/sybil_checker.py b/sybil_checker.py
index 52fba0c..daaf0bd 100755
--- a/sybil_checker.py
+++ b/sybil_checker.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright 2013, Damian Johnson and The Tor Project
+# Copyright 2013-2016, Damian Johnson and The Tor Project
 # See LICENSE for licensing information
 
 """
diff --git a/util.py b/util.py
index 9440d4c..483181e 100644
--- a/util.py
+++ b/util.py
@@ -15,6 +15,8 @@ FROM_ADDRESS = 'atagar at torproject.org'
 TO_ADDRESSES = ['tor-consensus-health at lists.torproject.org']
 ERROR_ADDRESS = 'atagar at torproject.org'
 
+TEST_RUN = False  # print script results rather than emailing
+
 
 def get_path(*comp):
   """
@@ -88,6 +90,13 @@ def send(subject, body, to = TO_ADDRESSES, cc = None, bcc = None):
   :raises: **Exception** if the email fails to be sent
   """
 
+  if TEST_RUN:
+    print('Email to: %s' % to)
+    print('Subject: %s' % subject)
+    print('-' * 60)
+    print(body)
+    return
+
   msg = MIMEMultipart('alternative')
   msg['Subject'] = subject
   msg['From'] = FROM_ADDRESS





More information about the tor-commits mailing list