From 9e30a9d18f400b75b955a6e79e714c724f35bed9 Mon Sep 17 00:00:00 2001 From: aeroniero33 Date: Tue, 14 Jun 2016 20:24:08 +0000 Subject: Updated update-seed to display the updated keys when it's used --- gkeys/gkeys/actions.py | 18 +++++++++++++++++- gkeys/gkeys/seedhandler.py | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py index d319964..fe45222 100644 --- a/gkeys/gkeys/actions.py +++ b/gkeys/gkeys/actions.py @@ -115,7 +115,9 @@ class Actions(ActionBase): category_msgs.extend(messages) return (True, category_msgs) print("Fetching seeds for %s category.\n" %args.category) + success, old_gkeys = self.listseed(args) fetch_success, fetch_messages = self.fetchseed(args) + self.seeds = None if fetch_success is not True: success = False messages = fetch_messages @@ -129,7 +131,21 @@ class Actions(ActionBase): success = False else: print("Update succeeded.\n") - messages = fetch_messages + ["Update operation:"] + [install_messages] + messages = fetch_messages + [" Update operation:"] + [install_messages] + success, new_gkeys = self.listseed(args) + added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys) + print("Updated revoked GKeys:") + if changed_gkeys: + for gkey in changed_gkeys: + self.output(['', changed_gkeys]) + else: + print("No GKeys were revoked") + print("Added GKeys:") + if added_gkeys: + for gkey in added_gkeys: + self.output(['', added_gkeys]) + else: + print("No GKeys were added") return (success, messages) def addseed(self, args): diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py index de2a6ad..993f260 100644 --- a/gkeys/gkeys/seedhandler.py +++ b/gkeys/gkeys/seedhandler.py @@ -70,6 +70,29 @@ class SeedHandler(object): if attr in GKEY._fields: keyinfo[attr] = None return keyinfo + + def compare_seeds(self, seeds1, seeds2) : + '''Compares two seed lists and returns the differences + + @param seeds1: set of seeds to be compared + @param seeds2: set of seeds to be compared + @return added_gkeys: list of keys that are included in seed2 but not seed1 + @return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered + ''' + old_gkeys = seeds1[1] + new_gkeys = seeds2[1] + changed_gkeys = [] + added_gkeys = [] + if old_gkeys: + for new_gkey in new_gkeys: + for old_gkey in old_gkeys: + if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey: + changed_gkeys.append(new_gkey) + if new_gkey not in old_gkeys and new_gkey not in changed_gkeys: + added_gkeys.append(new_gkey) + else: + added_gkeys = new_gkeys + return(added_gkeys, changed_gkeys) def load_seeds(self, seedfile=None, filepath=None, refresh=False): '''Load seed file -- cgit v1.2.3-65-gdbad