From aaedbe87684e3375b5d96baf9501ddb61e004c7c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 16 2017 08:12:07 +0000 Subject: 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:]))