[sysadmin-bin] Move these vars within each individual function



commit 1fb87fbc561970ad61292dc0637ced5d8d23e69e
Author: Andrea Veri <averi redhat com>
Date:   Mon Jan 25 15:36:44 2021 +0100

    Move these vars within each individual function

 membership/foundation-operations.py | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/membership/foundation-operations.py b/membership/foundation-operations.py
index 4c50f5e..6219ec8 100755
--- a/membership/foundation-operations.py
+++ b/membership/foundation-operations.py
@@ -52,12 +52,11 @@ except IOError as e:
 
 glu = Glu.Gnome_ldap_utils(LDAP_GROUP_BASE, LDAP_HOST, LDAP_USER_BASE, LDAP_USER, LDAP_PASSWORD)
 
-today = dt.date.today()
-foundationmembers = glu.get_uids_from_group('foundation')
-
 
 def send_renewal_emails():
-    _today = str(today)
+    today = str(dt.date.today())
+
+    foundationmembers = glu.get_uids_from_group('foundation')
 
     for member in foundationmembers:
         ldap_fields = glu.get_attributes_from_ldap(member, 'FirstAdded', 'LastRenewedOn', 'mail', 'cn')
@@ -69,18 +68,22 @@ def send_renewal_emails():
         userid_attr = ldap_fields[0].decode()
 
         if (first_added_attr and last_renewed_on_attr):
-            if (last_renewed_on_attr == _today) and (first_added_attr == _today):
+            if (last_renewed_on_attr == today) and (first_added_attr == today):
                 send_form_letters(new_member_form_letter, mail_attr, common_name_attr, userid_attr)
-            elif last_renewed_on_attr == _today:
+            elif last_renewed_on_attr == today:
                 send_form_letters(renewal_form_letter, mail_attr, common_name_attr)
 
 
 def remove_expired_memberships_from_foundation():
+    today = str(dt.date.today())
+
     import dateutil.relativedelta as relativedelta
     delta_2y = relativedelta.relativedelta(years=2)
     delta_1m = relativedelta.relativedelta(months=1)
     members_list = ''
 
+    foundationmembers = glu.get_uids_from_group('foundation')
+
     for member in foundationmembers:
         ldap_fields = glu.get_attributes_from_ldap(member, 'LastRenewedOn', 'mail', 'cn')
 
@@ -106,6 +109,7 @@ def remove_expired_memberships_from_foundation():
 def generate_membership_list():
     import json
 
+    foundationmembers = glu.get_uids_from_group('foundation')
     emeritus = glu.get_uids_from_group('emeritus')
 
     result = { 'members': [], 'emeritus': [] }
@@ -134,6 +138,8 @@ def generate_membership_list():
 
 
 def send_form_letters(form_letter, email, name, *args):
+    today = str(dt.date.today())
+
     year_month = str(today.year) + '-' + str(today.month)
 
     try:
@@ -167,13 +173,15 @@ def send_form_letters(form_letter, email, name, *args):
 
 
 def subscribe_new_members():
-    _today = str(today)
+    today = str(dt.date.today())
 
     if socket.gethostname() != 'restaurant.gnome.org':
         sys.exit("This function should only be used on restaurant.gnome.org")
 
     f = open('/tmp/new_subscribers', 'w')
 
+    foundationmembers = glu.get_uids_from_group('foundation')
+
     for member in foundationmembers:
         ldap_fields = glu.get_attributes_from_ldap(member, 'FirstAdded', 'LastRenewedOn', 'uid')
         first_added_attr = ldap_fields[1]
@@ -181,9 +189,9 @@ def subscribe_new_members():
         uid_attr = ldap_fields[3]
         gnome_alias = '%s gnome org' % (uid_attr)
 
-        if first_added_attr == _today:
+        if first_added_attr == today:
             f.write(str(gnome_alias) + '\n')
-        elif last_renewed_on_attr == _today:
+        elif last_renewed_on_attr == today:
             f.write(str(gnome_alias) + '\n')
         else:
             pass


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