mirror_project_in.py 1.5 KB

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