From ff9605eacca9b71f5e7495a9fa5f8a17973b5b05 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 16 2017 08:11:58 +0000 Subject: [PATCH 1/5] Move the pagure_poc script into a scripts folder Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure_poc.py b/pagure_poc.py deleted file mode 100644 index 026c8bb..0000000 --- a/pagure_poc.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- 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(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:])) diff --git a/scripts/pagure_poc.py b/scripts/pagure_poc.py new file mode 100644 index 0000000..026c8bb --- /dev/null +++ b/scripts/pagure_poc.py @@ -0,0 +1,68 @@ +# -*- 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(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:])) From cc86f658dc03a0ed11f4ba1612a758115195222e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 16 2017 08:12:03 +0000 Subject: [PATCH 2/5] Include the scripts folder in the releases Signed-off-by: Pierre-Yves Chibon --- diff --git a/MANIFEST.in b/MANIFEST.in index 1886ae2..c1871c2 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,4 +4,5 @@ include dist_git_auth.py include dist_git_auth_tests.py include pagure_poc.py recursive-include template * +recursive-include scripts * recursive-include static * From 9dfa24bdebfa4ed991c42d7409520372b79e9a2c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 16 2017 08:12:05 +0000 Subject: [PATCH 3/5] Install all the cron scripts in the spec file Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure-dist-git.spec b/pagure-dist-git.spec index 22c792a..07b388f 100644 --- a/pagure-dist-git.spec +++ b/pagure-dist-git.spec @@ -101,9 +101,9 @@ install -p -m 644 template/*.html $RPM_BUILD_ROOT/%{_datadir}/pagure_dist_git/te 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 +# Install the different 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/ +install -p -m 644 scripts/*.py $RPM_BUILD_ROOT/%{_libexecdir}/pagure-dist-git/ # The tests require network access, so don't run them. From aaedbe87684e3375b5d96baf9501ddb61e004c7c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 16 2017 08:12:07 +0000 Subject: [PATCH 4/5] Add a script outputting for each project the people who should be CC'ed This will allow to speed up the sync of the watch issues on bugzilla Signed-off-by: Pierre-Yves Chibon --- diff --git a/scripts/pagure_bz.py b/scripts/pagure_bz.py new file mode 100644 index 0000000..a8252b9 --- /dev/null +++ b/scripts/pagure_bz.py @@ -0,0 +1,93 @@ +# -*- 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(args): + """ Creates a JSON blob containing the following structure: + { + namespace: { + package: [people watching issues], + ... + }, + ... + } + """ + 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 + + # Start the watchers by the 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] = set([admin]) + + # Add the explicit watchers + + query = pagure.SESSION.query( + model.Project.namespace, model.Project.name, model.User.user, + model.Watcher.watch_issues, + ).filter( + model.Project.id == model.Watcher.project_id + ).filter( + model.Watcher.user_id == model.User.id + ) + + for entry in query.all(): + namespace, package, user, watch_issue = entry + if watch_issue: + output[namespace][package].add(user) + elif user in output[namespace][package]: + output[namespace][package].remove(user) + + # Convert the sets into lists + final = collections.defaultdict(dict) + for ns in output: + for pkg in output[ns]: + final[ns][pkg] = list(output[ns][pkg]) + + with open(os.path.join(args[0], 'pagure_bz.json'), 'w') as stream: + json.dump(final, stream, indent=4, sort_keys=True) + + +if __name__ == '__main__': + import sys + sys.exit(main(sys.argv[1:])) From 264dd220b29801bcb3c360743a0d764918b90738 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 16 2017 08:12:07 +0000 Subject: [PATCH 5/5] Add a script outputting for each project the user to put on the -owner alias This will allow to speed up the creation of the -owner aliases Signed-off-by: Pierre-Yves Chibon --- diff --git a/scripts/pagure_owner_alias.py b/scripts/pagure_owner_alias.py new file mode 100644 index 0000000..76417c5 --- /dev/null +++ b/scripts/pagure_owner_alias.py @@ -0,0 +1,91 @@ +# -*- 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(args): + """ Creates a JSON blob containing the following structure: + { + namespace: { + package: [people watching issues], + ... + }, + ... + } + """ + 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 + + # Start the owner list by the 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] = set([admin]) + + # Add the users with commit and admin ACLs + + query = pagure.SESSION.query( + model.Project.namespace, model.Project.name, model.User.user, + ).filter( + model.Project.id == model.ProjectUser.project_id + ).filter( + model.ProjectUser.user_id == model.User.id + ).filter( + model.ProjectUser.access.in_(['commit', 'admin']) + ) + + for entry in query.all(): + namespace, package, user = entry + output[namespace][package].add(user) + + # Convert the sets into lists + final = collections.defaultdict(dict) + for ns in output: + for pkg in output[ns]: + final[ns][pkg] = list(output[ns][pkg]) + + with open(os.path.join(args[0], 'pagure_owner_alias.json'), 'w') as stream: + json.dump(final, stream, indent=4, sort_keys=True) + + +if __name__ == '__main__': + import sys + sys.exit(main(sys.argv[1:]))