From 7b8e327dd4b2e44ae9c69d82a1d561631f310302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20M=C3=A4der?= <maeder@phys.ethz.ch> Date: Thu, 29 Mar 2018 18:48:45 +0200 Subject: [PATCH] Add sort function --- bin/showgroup.py | 2 +- lib/isg/dphysldap.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/showgroup.py b/bin/showgroup.py index b6daaaf..55edd9b 100755 --- a/bin/showgroup.py +++ b/bin/showgroup.py @@ -42,7 +42,7 @@ def main(): sys.exit('No groups found.') if len(groups) != 1: - #groups.sort('cn') + groups.sort('cn') groups.remove_attrs([v for k, v in NOOPTS.items() if args[k]]) print(groups) diff --git a/lib/isg/dphysldap.py b/lib/isg/dphysldap.py index 72b26f8..171b160 100644 --- a/lib/isg/dphysldap.py +++ b/lib/isg/dphysldap.py @@ -160,8 +160,19 @@ class Entries(list): table = [[e[a] for a in self.attrs] for e in self] return tabulate.tabulate(table, tablefmt=FMT, headers=self.attrs) - #def sort(self, attr): - # self = sorted(self, key=lambda k: k[attr].__str__()) + def sort(self, attr): + super().sort(key=lambda k: str(k[attr])) + + # def l(k): + # return str(k[attr]) + + # l = [] + # for i in self: + # criteria = l(i) + # l.append(criteria) + + # return sorted(l, ) + def remove_attr(self, attr): if attr in self.attrs: -- GitLab