#3702 Adding 'list-groups' function to pagure-admin
Closed 2 years ago by arrfab. Opened 2 years ago by arrfab.

file modified
+31

@@ -320,6 +320,19 @@ 

      local_parser.set_defaults(func=do_new_group)

  

  

+ def _parser_list_groups(subparser):

+     """ Set up the CLI argument parser for the list-groups action.

+ 

+     :arg subparser: an argparse subparser allowing to have action's specific

+         arguments

+ 

+     """

+     local_parser = subparser.add_parser(

+         "list-groups", help="Lists existing groups on this pagure instance"

+     )

+     local_parser.set_defaults(func=do_list_groups)

+ 

+ 

  def _parser_block_user(subparser):

      """ Set up the CLI argument parser for the block-user action.

  

@@ -416,6 +429,9 @@ 

      # new-group

      _parser_new_group(subparser)

  

+     # list-groups

+     _parser_list_groups(subparser)

+ 

      # block-user

      _parser_block_user(subparser)

  

@@ -863,6 +879,21 @@ 

      print("Group `%s` created." % args.group_name)

      print(msg)

  

+ def do_list_groups(args):

+     """ Lists existing groups in this pagure instance.

+ 

+     :arg args: the argparse object returned by ``parse_arguments()``.

+ 

+     """

+ 

+     msg = pagure.lib.search_groups(

+         session=session,

+     )

+     session.commit()

No need to commit since nothing is changed ;-)

+     print("List of groups on this Pagure instance:" )

+     for group in msg:

+       print(group)

+ 

  

  def do_block_user(args):

      """ Block the specified user from all interactions with pagure until the

This commit add the "list-groups" function to pagure-admin cli tool.
Actually pagure-admin has "new-group" function but nothing to list existing groups.
Instead of abusing the API (through /api/0/groups) calls, a pagure admin scripting something with pagure-admin can retrieve groups and eventually take other actions (like adding missing group, etc)

No need to commit since nothing is changed ;-)

Pull-Request has been closed by arrfab

2 years ago