#39 Move the cron scripts into a scripts folder and add a couple more
Merged 7 years ago by pingou. Opened 7 years ago by pingou.

file modified
+1
@@ -4,4 +4,5 @@ 

  include dist_git_auth_tests.py

  include pagure_poc.py

  recursive-include template *

+ recursive-include scripts *

  recursive-include static *

file modified
+2 -2
@@ -101,9 +101,9 @@ 

  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.

file added
+93
@@ -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:]))

@@ -0,0 +1,91 @@ 

+ # -*- 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 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:]))

scripts/pagure_poc.py pagure_poc.py
file renamed
file was moved with no change to the file