Repository: regro/regolith

Issue:
helper group member lister

Discussion:

Patch:
diff --git a/news/membershelper.rst b/news/membershelper.rst
new file mode 100644
index 00000000..aa86eb16
--- /dev/null
+++ b/news/membershelper.rst
@@ -0,0 +1,12 @@
+**Added:**
+    * A lister for the names of members of the group, either current or ever.
+
+**Changed:** None
+
+**Deprecated:** None
+
+**Removed:** None
+
+**Fixed:** None
+
+**Security:** None
diff --git a/regolith/helper.py b/regolith/helper.py
index d2d197e4..95b69cda 100644
--- a/regolith/helper.py
+++ b/regolith/helper.py
@@ -7,6 +7,7 @@ from regolith.helpers import a_projectumhelper as a_projectum
 from regolith.helpers import l_milestoneshelper as l_milestone
 from regolith.helpers import l_projectahelper as l_projecta
 from regolith.helpers import l_grantshelper as l_grants
+from regolith.helpers import l_membershelper as l_members
 
 HELPERS = {
     "hello": (hello.HelloHelper, hello.subparser),
@@ -16,6 +17,7 @@ HELPERS = {
     "l_milestones": (l_milestone.MilestonesListerHelper, l_milestone.subparser),
     "l_projecta": (l_projecta.ProjectaListerHelper, l_projecta.subparser),
     "l_grants": (l_grants.GrantsListerHelper, l_grants.subparser),
+    "l_members": (l_members.MembersListerHelper, l_members.subparser),
 }
 
 
diff --git a/regolith/helpers/l_membershelper.py b/regolith/helpers/l_membershelper.py
new file mode 100644
index 00000000..a81b36a9
--- /dev/null
+++ b/regolith/helpers/l_membershelper.py
@@ -0,0 +1,81 @@
+"""Helper for listing group members.
+
+"""
+import datetime as dt
+import dateutil.parser as date_parser
+from dateutil.relativedelta import relativedelta
+import sys
+
+from regolith.dates import get_due_date
+from regolith.helpers.basehelper import SoutHelperBase
+from regolith.fsclient import _id_key
+from regolith.tools import (
+    all_docs_from_collection,
+    get_pi_id,
+)
+
+TARGET_COLL = "people"
+HELPER_TARGET = "l_members"
+ALLOWED_STATI = ["proposed", "started", "finished", "back_burner", "paused", "cancelled"]
+
+
+
+def subparser(subpi):
+    subpi.add_argument("-v", "--verbose", action="store_true", help='increase verbosity of output')
+    subpi.add_argument("-c", "--current", action="store_true", help='get only current group members ')
+
+    return subpi
+
+
+class MembersListerHelper(SoutHelperBase):
+    """Helper for listing group members.
+
+    """
+    # btype must be the same as helper target in helper.py
+    btype = HELPER_TARGET
+    needed_dbs = [f'{TARGET_COLL}']
+
+    def construct_global_ctx(self):
+        """Constructs the global context"""
+        super().construct_global_ctx()
+        gtx = self.gtx
+        rc = self.rc
+        if "groups" in self.needed_dbs:
+            rc.pi_id = get_pi_id(rc)
+        rc.coll = f"{TARGET_COLL}"
+        try:
+            if not rc.database:
+                rc.database = rc.databases[0]["name"]
+        except:
+            pass
+        colls = [
+            sorted(
+                all_docs_from_collection(rc.client, collname), key=_id_key
+            )
+            for collname in self.needed_dbs
+        ]
+        for db, coll in zip(self.needed_dbs, colls):
+            gtx[db] = coll
+        gtx["all_docs_from_collection"] = all_docs_from_collection
+        gtx["float"] = float
+        gtx["str"] = str
+        gtx["zip"] = zip
+
+
+    def sout(self):
+        rc = self.rc
+        bad_stati = ["finished", "cancelled", "paused", "back_burner"]
+        people = []
+        for person in self.gtx["people"]:
+            if rc.current and not person.get('active'):
+                continue
+            people.append(person)
+        #people.sort()
+        for i in people:
+            if rc.verbose:
+                print("{}, {} | group_id: {} | orcid: {} | github_id: {}".format(i.get('name'), i.get('position'), i.get('_id'), i.get('orcid_id'),
+                                                  i.get('github_id')))
+            else:
+                print("{}".format(i.get('name')))
+        return
+


Test patch:
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index aea09014..322bcaec 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -35,6 +35,9 @@ helper_map = [
     (["helper", "l_grants", "-c", "-d", "2020-05-25"],
      "sym2.0, awardnr: , acctn: , 2019-06-01 to 2030-12-31\n, awardnr: , acctn: GG012345, 2015-10-01 to 2025-09-30\n"
      ),
+    (["helper", "l_members", "-v"],
+     "Anthony Scopatz, professor | group_id: scopatz | orcid: 0000-0002-9432-4248 | github_id: ascopatz\n"
+     ),
 
 ]