Skip to content

Commit

Permalink
ManualOverride: Add update_dataframes function #31
Browse files Browse the repository at this point in the history
  • Loading branch information
astrochun committed Jul 14, 2020
1 parent 33603a7 commit ce16056
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions requiam/manual_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class ManualOverride:
"""
Purpose:
This class handles manual override changes. It reads in CSV
configuration files and queries pandas DataFrame
to identify additions and deletions. Employ set operations for
simplicity
configuration files and queries pandas DataFrame to identify additions
and deletions. Employ set operations for simplicity. It also update
the pandas DataFrame
Attributes
----------
Expand Down Expand Up @@ -77,6 +77,35 @@ def identify_changes(self, ldap_set, group, group_type):

return new_ldap_set

def update_dataframe(self, netid, uaid, group, group_type):
"""Update pandas DataFrame with necessary changes"""

if group_type not in ['portal', 'quota']:
raise ValueError("Incorrect [group_type] input")

if group_type == 'portal':
revised_df = self.portal_df
if group_type == 'quota':
revised_df = self.quota_df

loc0 = revised_df.loc[revised_df['netid'] == netid].index
if len(loc0) == 0:
print(f"Adding entry for {netid}")
revised_df.loc[len(revised_df)] = [netid, uaid, group]
else:
print(f"Updating entry for {netid}")
revised_df.loc[loc0[0]] = [netid, uaid, group]

if group_type == 'portal':
self.portal_df = revised_df
print("Update portal csv")
self.portal_df.to_csv(self.portal_file)

if group_type == 'quota':
self.quota_df = revised_df
print("Update quota csv")
self.quota_df.to_csv(self.portal_file)


def read_manual_file(input_file):
"""
Expand Down

0 comments on commit ce16056

Please sign in to comment.