From 9fc2ba435c39806ad2b9baa7589c5330d545727c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 28 2017 17:26:10 +0000 Subject: [PATCH 1/4] Add a small script dumping the main admins of each project in pagure 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 --- diff --git a/pagure_poc.py b/pagure_poc.py new file mode 100644 index 0000000..93d042f --- /dev/null +++ b/pagure_poc.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2017 - Copyright Red Hat Inc + + Authors: The Dream Team + Pierre-Yves Chibon + +""" +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(): + """ Creates a JSON blob containing the following structure: + { + namespace: { + package: main admin, + ... + }, + ... + } + """ + 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('pagure_poc.json', 'w') as stream: + json.dump(output, stream, indent=4, sort_keys=True) + + +if __name__ == '__main__': + import sys + sys.exit(main()) From dced9dff46dce18935b8dad20e576289af8328f8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 29 2017 12:13:38 +0000 Subject: [PATCH 2/4] Ensure that the script is given an place where to put its output Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure_poc.py b/pagure_poc.py index 93d042f..026c8bb 100644 --- a/pagure_poc.py +++ b/pagure_poc.py @@ -25,7 +25,7 @@ from pagure.lib import model # noqa: E402 _log = logging.getLogger(__name__) -def main(): +def main(args): """ Creates a JSON blob containing the following structure: { namespace: { @@ -35,6 +35,18 @@ def main(): ... } """ + 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( @@ -47,10 +59,10 @@ def main(): namespace, package, admin = entry output[namespace][package] = admin - with open('pagure_poc.json', 'w') as stream: + 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.exit(main(sys.argv[1:])) From 6b93eac96413a85f7156f0cd0f6a0c6ce07af8f7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 29 2017 14:35:29 +0000 Subject: [PATCH 3/4] Install the pagure_poc script --- diff --git a/pagure-dist-git.spec b/pagure-dist-git.spec index 36c8850..a643e4a 100644 --- a/pagure-dist-git.spec +++ b/pagure-dist-git.spec @@ -102,6 +102,10 @@ install -p -m 644 template/index.html $RPM_BUILD_ROOT/%{_datadir}/pagure_dist_gi 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 @@ install -p -m 644 static/pagure-logo.png $RPM_BUILD_ROOT/%{_datadir}/pagure_dist %{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 @@ install -p -m 644 static/pagure-logo.png $RPM_BUILD_ROOT/%{_datadir}/pagure_dist %{python3_sitelib}/dist_git_auth.py* %{python3_sitelib}/pagure_dist_git-%{version}* %{_datadir}/pagure_dist_git/ +%{_libexecdir}/pagure-dist-git/ %endif From e75970b090b72be8457c86074b0e29203f377dca Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 29 2017 14:37:19 +0000 Subject: [PATCH 4/4] Include pagure_poc in the release --- diff --git a/MANIFEST.in b/MANIFEST.in index d87779f..1886ae2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,5 +2,6 @@ include LICENSE include README.rst include dist_git_auth.py include dist_git_auth_tests.py +include pagure_poc.py recursive-include template * recursive-include static *