mirror_project_in.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. from __future__ import print_function, absolute_import
  3. import os
  4. import argparse
  5. from datetime import datetime, timedelta
  6. from sqlalchemy.exc import SQLAlchemyError
  7. import pagure.config
  8. import pagure.lib.model as model
  9. import pagure.lib.model_base
  10. import pagure.lib.notify
  11. import pagure.lib.query
  12. if 'PAGURE_CONFIG' not in os.environ \
  13. and os.path.exists('/etc/pagure/pagure.cfg'):
  14. print('Using configuration file `/etc/pagure/pagure.cfg`')
  15. os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg'
  16. _config = pagure.config.reload_config()
  17. def main(check=False, debug=False):
  18. ''' The function pulls in all the changes from upstream'''
  19. session = pagure.lib.model_base.create_session(_config['DB_URL'])
  20. projects = session.query(
  21. model.Project
  22. ).filter(
  23. model.Project.mirrored_from != None
  24. ).all()
  25. for project in projects:
  26. if debug:
  27. print("Mirrorring %s" % project.fullname)
  28. pagure.lib.git.mirror_pull_project(session, project, debug=debug)
  29. session.remove()
  30. if debug:
  31. print('Done')
  32. if __name__ == '__main__':
  33. parser = argparse.ArgumentParser(
  34. description='Script to send email before the api token expires')
  35. parser.add_argument(
  36. '--check', dest='check', action='store_true', default=False,
  37. help='Print the some output but does not send any email')
  38. parser.add_argument(
  39. '--debug', dest='debug', action='store_true', default=False,
  40. help='Print the debugging output')
  41. args = parser.parse_args()
  42. main(debug=args.debug)