[sysadmin-bin] Make use of the same script for handling all the foundation operations, introduce options



commit 84fbec7a72584321be460c676c88dd41114369f3
Author: Andrea Veri <av gnome org>
Date:   Sat Sep 27 23:35:10 2014 +0200

    Make use of the same script for handling all the foundation operations, introduce options

 membership/foundation-operations.py |   64 ++++++++++++++++++++++++++++++++--
 1 files changed, 60 insertions(+), 4 deletions(-)
---
diff --git a/membership/foundation-operations.py b/membership/foundation-operations.py
index 304000e..e2ad9c5 100755
--- a/membership/foundation-operations.py
+++ b/membership/foundation-operations.py
@@ -1,11 +1,28 @@
 #!/usr/bin/python
 
 import ldap
+import socket
 import ldap.filter
-import calendar
+import smtplib
+import sys
+import os
 from email.mime.text import MIMEText
 from time import strftime, gmtime
-import smtplib
+from optparse import OptionParser
+
+usage = "usage: %prog [options]"
+parser = OptionParser(usage)
+
+parser.add_option("--send-form-letters",
+                  action="store_true", default=False,
+                  help="Checks for LastRenewedOn / FirstAdded fields and send "
+                       "welcome emails to new or existing Foundation members accordingly")
+parser.add_option("--automatic-subscriptions",
+                  action="store_true", default=False,
+                  help="Automatically subscribes new Foundation members to the foundation-announce "
+                       "mailing list. To be executed on smtp.gnome.org")
+
+(options, args) = parser.parse_args()
 
 LDAP_GROUP_BASE='cn=groups,cn=accounts,dc=gnome,dc=org'
 LDAP_USER_BASE='cn=users,cn=accounts,dc=gnome,dc=org'
@@ -63,7 +80,7 @@ def _get_attributes_from_ldap(uid, attr):
 
         return foundationmembership
 
-def _get_last_renewed_on():
+def _get_foundation_fields_from_ldap():
     foundationmembers = _get_foundation_members()
 
     for member in foundationmembers:
@@ -77,7 +94,7 @@ def _get_last_renewed_on():
         elif last_renewed_on_attr[member] == TODAY:
            send_form_letters(renewal_form_letter, mail_attr[member], common_name_attr[member])
         else:
-           continue
+           pass
 
 def send_form_letters(form_letter, email, name):
     try:
@@ -188,3 +205,42 @@ Thanks for your contributions to GNOME.
 Best wishes,
 
 The GNOME Foundation Membership Committee"""
+
+def subscribe_new_members():
+    if socket.gethostname() != 'restaurant.gnome.org':
+        sys.exit("This function should only be used on restaurant.gnome.org")
+
+    foundationmembers = _get_foundation_members()
+
+    f = open('/tmp/new_subscribers', 'w')
+
+    for member in foundationmembers:
+        first_added_attr = _get_attributes_from_ldap(member, 'FirstAdded')
+        last_renewed_on_attr = _get_attributes_from_ldap(member, 'LastRenewedOn')
+        mail_attr = _get_attributes_from_ldap(member,'mail')
+
+        if first_added_attr[member] == TODAY:
+            f.write(str(mail_attr[member]) + '\n')
+        elif last_renewed_on_attr[member] == TODAY:
+            f.write(str(mail_attr[member]) + '\n')
+        else:
+            pass
+
+    f.close()
+
+    if os.path.getsize('/tmp/new_subscribers') == 0:
+        os.remove('/tmp/new_subscribers')
+    else:
+        subscribe = subprocess.Popen(['/usr/lib/mailman/bin/add_members', '-a', 'n', '-r', 
'/tmp/new_subscribers', 'foundation-announce'])
+        subscribe.wait()
+        os.remove('/tmp/new_subscribers')
+
+def main():
+    if options.send_form_letters:
+        _get_foundation_fields_from_ldap()
+
+    if options.automatic_subscriptions:
+        subscribe_new_members()
+
+if __name__ == "__main__":
+    main()


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