#29 Add a small script dumping the main admins of each project in pagure
Merged 8 years ago by pingou. Opened 8 years ago by pingou.

file modified
+1
@@ -2,5 +2,6 @@ 

  include README.rst

  include dist_git_auth.py

  include dist_git_auth_tests.py

+ include pagure_poc.py

  recursive-include template *

  recursive-include static *

file modified
+6
@@ -102,6 +102,10 @@ 

  mkdir -p $RPM_BUILD_ROOT/%{_datadir}/pagure_dist_git/static/

  install -p -m 644 static/pagure-logo.png $RPM_BUILD_ROOT/%{_datadir}/pagure_dist_git/static/

  

+ # Install the cron job scripts

+ mkdir -p $RPM_BUILD_ROOT/%{_libexecdir}/pagure-dist-git/

+ install -p -m 644 pagure_poc.py $RPM_BUILD_ROOT/%{_libexecdir}/pagure-dist-git/

+ 

  

  # The tests require network access, so don't run them.

  #%%check
@@ -116,6 +120,7 @@ 

  %{python2_sitelib}/dist_git_auth.py*

  %{python2_sitelib}/pagure_dist_git-%{version}*

  %{_datadir}/pagure_dist_git/

+ %{_libexecdir}/pagure-dist-git/

  

  %if 0%{?with_python3}

  %files -n python3-%{modname}
@@ -124,6 +129,7 @@ 

  %{python3_sitelib}/dist_git_auth.py*

  %{python3_sitelib}/pagure_dist_git-%{version}*

  %{_datadir}/pagure_dist_git/

+ %{_libexecdir}/pagure-dist-git/

  %endif

  

  

file added
+68
@@ -0,0 +1,68 @@ 

+ # -*- coding: utf-8 -*-

+ 

+ """

+  (c) 2017 - Copyright Red Hat Inc

+ 

+  Authors:  The Dream Team

+    Pierre-Yves Chibon <pingou@pingoured.fr>

+ 

+ """

+ from __future__ import print_function

+ 

+ import collections

+ import json

+ import logging

+ import os

+ 

+ if 'PAGURE_CONFIG' not in os.environ \

+         and os.path.exists('/etc/pagure/pagure.cfg'):

+     os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'

+ 

+ import pagure  # noqa: E402

+ from pagure.lib import model  # noqa: E402

+ 

+ 

+ _log = logging.getLogger(__name__)

+ 

+ 

+ def main(args):

+     """ Creates a JSON blob containing the following structure:

+     {

+       namespace: {

+         package: main admin,

+         ...

+       },

+       ...

+     }

+     """

+     if len(args) != 1:

+         print(

+             'Please specify the folder where to place the output, and only'

+             ' that')

+         return 1

+     if not os.path.exists(args[0]):

+         print('%s does not appear to exist' % args[0])

+         return 2

+     if not os.path.isdir(args[0]):

+         print('%s does not appear to be a directory' % args[0])

+         return 3

+ 

+     query = pagure.SESSION.query(

+         model.Project.namespace, model.Project.name, model.User.user

+     ).filter(

+         model.Project.user_id == model.User.id

+     )

+ 

+     output = collections.defaultdict(dict)

+ 

+     for entry in query.all():

+         namespace, package, admin = entry

+         output[namespace][package] = admin

+ 

+     with open(os.path.join(args[0], 'pagure_poc.json'), 'w') as stream:

+         json.dump(output, stream, indent=4, sort_keys=True)

+ 

+ 

+ if __name__ == '__main__':

+     import sys

+     sys.exit(main(sys.argv[1:]))

This can then be run via a cron job and exposed somewhere for tools to
consume.

Fixes https://pagure.io/pagure/issue/2618

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto 7d401fd47e6023b827d977208c563fe5df0380da

8 years ago

rebased onto 9fc2ba4

8 years ago

1 new commit added

  • Ensure that the script is given an place where to put its output
8 years ago

1 new commit added

  • Install the pagure_poc script
8 years ago

1 new commit added

  • Include pagure_poc in the release
8 years ago

:+1: to the concept.

Pull-Request has been merged by pingou

8 years ago