1
0

mirror_project_in.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 and os.path.exists(
  13. "/etc/pagure/pagure.cfg"
  14. ):
  15. print("Using configuration file `/etc/pagure/pagure.cfg`")
  16. os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
  17. _config = pagure.config.reload_config()
  18. def main(check=False, debug=False):
  19. """ The function pulls in all the changes from upstream"""
  20. session = pagure.lib.model_base.create_session(_config["DB_URL"])
  21. projects = (
  22. session.query(model.Project)
  23. .filter(model.Project.mirrored_from != None)
  24. .all()
  25. )
  26. for project in projects:
  27. if debug:
  28. print("Mirrorring %s" % project.fullname)
  29. try:
  30. pagure.lib.git.mirror_pull_project(session, project, debug=debug)
  31. except Exception as err:
  32. print("ERROR: %s" % err)
  33. session.remove()
  34. if debug:
  35. print("Done")
  36. if __name__ == "__main__":
  37. parser = argparse.ArgumentParser(
  38. description="Script to send email before the api token expires"
  39. )
  40. parser.add_argument(
  41. "--check",
  42. dest="check",
  43. action="store_true",
  44. default=False,
  45. help="Print the some output but does not send any email",
  46. )
  47. parser.add_argument(
  48. "--debug",
  49. dest="debug",
  50. action="store_true",
  51. default=False,
  52. help="Print the debugging output",
  53. )
  54. args = parser.parse_args()
  55. main(debug=args.debug)