1
0

mirror_project_in.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python
  2. from __future__ import print_function, absolute_import
  3. import os
  4. import argparse
  5. import pagure.config
  6. import pagure.lib.model as model
  7. import pagure.lib.model_base
  8. import pagure.lib.notify
  9. import pagure.lib.query
  10. if "PAGURE_CONFIG" not in os.environ and os.path.exists(
  11. "/etc/pagure/pagure.cfg"
  12. ):
  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(debug=False):
  17. """The function pulls in all the changes from upstream"""
  18. session = pagure.lib.model_base.create_session(_config["DB_URL"])
  19. projects = (
  20. session.query(model.Project)
  21. .filter(model.Project.mirrored_from is not None)
  22. .all()
  23. )
  24. for project in projects:
  25. if debug:
  26. print("Mirrorring %s" % project.fullname)
  27. try:
  28. pagure.lib.git.mirror_pull_project(session, project, debug=debug)
  29. except Exception as err:
  30. print("ERROR: %s" % err)
  31. session.remove()
  32. if debug:
  33. print("Done")
  34. if __name__ == "__main__":
  35. parser = argparse.ArgumentParser(
  36. description="Script to PULL external repos into local (mirroring)"
  37. )
  38. parser.add_argument(
  39. "--debug",
  40. dest="debug",
  41. action="store_true",
  42. default=False,
  43. help="Print the debugging output",
  44. )
  45. args = parser.parse_args()
  46. main(debug=args.debug)