| |
@@ -0,0 +1,93 @@
|
| |
+ # -*- 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: [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:]))
|
| |