Blame files/mirror_project_in.py

Pierre-Yves Chibon 227f4c
#!/usr/bin/env python
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 67d1cc
from __future__ import print_function, absolute_import
Pierre-Yves Chibon 227f4c
import os
Pierre-Yves Chibon 227f4c
import argparse
Pierre-Yves Chibon 227f4c
from datetime import datetime, timedelta
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
from sqlalchemy.exc import SQLAlchemyError
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
import pagure.config
Pierre-Yves Chibon 227f4c
import pagure.lib.model as model
Pierre-Yves Chibon cf98be
import pagure.lib.model_base
Pierre-Yves Chibon cf98be
import pagure.lib.notify
Pierre-Yves Chibon cf98be
import pagure.lib.query
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
if "PAGURE_CONFIG" not in os.environ and os.path.exists(
Pierre-Yves Chibon 73d120
    "/etc/pagure/pagure.cfg"
Pierre-Yves Chibon 73d120
):
Pierre-Yves Chibon 73d120
    print("Using configuration file `/etc/pagure/pagure.cfg`")
Pierre-Yves Chibon 73d120
    os.environ["PAGURE_CONFIG"] = "/etc/pagure/pagure.cfg"
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
_config = pagure.config.reload_config()
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
def main(check=False, debug=False):
Pierre-Yves Chibon 73d120
    """ The function pulls in all the changes from upstream"""
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
    session = pagure.lib.model_base.create_session(_config["DB_URL"])
Pierre-Yves Chibon 73d120
    projects = (
Pierre-Yves Chibon 73d120
        session.query(model.Project)
Pierre-Yves Chibon 73d120
        .filter(model.Project.mirrored_from != None)
Pierre-Yves Chibon 73d120
        .all()
Pierre-Yves Chibon 73d120
    )
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
    for project in projects:
Pierre-Yves Chibon 227f4c
        if debug:
Pierre-Yves Chibon 227f4c
            print("Mirrorring %s" % project.fullname)
Pierre-Yves Chibon cea8e2
        try:
Pierre-Yves Chibon cea8e2
            pagure.lib.git.mirror_pull_project(session, project, debug=debug)
Pierre-Yves Chibon cea8e2
        except Exception as err:
Pierre-Yves Chibon cea8e2
            print("ERROR: %s" % err)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
    session.remove()
Pierre-Yves Chibon 227f4c
    if debug:
Pierre-Yves Chibon 73d120
        print("Done")
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon 227f4c
    parser = argparse.ArgumentParser(
Pierre-Yves Chibon 73d120
        description="Script to send email before the api token expires"
Pierre-Yves Chibon 73d120
    )
Pierre-Yves Chibon 227f4c
    parser.add_argument(
Pierre-Yves Chibon 73d120
        "--check",
Pierre-Yves Chibon 73d120
        dest="check",
Pierre-Yves Chibon 73d120
        action="store_true",
Pierre-Yves Chibon 73d120
        default=False,
Pierre-Yves Chibon 73d120
        help="Print the some output but does not send any email",
Pierre-Yves Chibon 73d120
    )
Pierre-Yves Chibon 227f4c
    parser.add_argument(
Pierre-Yves Chibon 73d120
        "--debug",
Pierre-Yves Chibon 73d120
        dest="debug",
Pierre-Yves Chibon 73d120
        action="store_true",
Pierre-Yves Chibon 73d120
        default=False,
Pierre-Yves Chibon 73d120
        help="Print the debugging output",
Pierre-Yves Chibon 73d120
    )
Pierre-Yves Chibon 227f4c
    args = parser.parse_args()
Pierre-Yves Chibon 227f4c
    main(debug=args.debug)