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 227f4c
if 'PAGURE_CONFIG' not in os.environ \
Pierre-Yves Chibon 227f4c
        and os.path.exists('/etc/pagure/pagure.cfg'):
Pierre-Yves Chibon 227f4c
    print('Using configuration file `/etc/pagure/pagure.cfg`')
Pierre-Yves Chibon 227f4c
    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 227f4c
    ''' The function pulls in all the changes from upstream'''
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon cf98be
    session = pagure.lib.model_base.create_session(_config['DB_URL'])
Pierre-Yves Chibon 227f4c
    projects = session.query(
Pierre-Yves Chibon 227f4c
        model.Project
Pierre-Yves Chibon 227f4c
    ).filter(
Pierre-Yves Chibon 227f4c
        model.Project.mirrored_from != None
Pierre-Yves Chibon 227f4c
    ).all()
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 227f4c
        pagure.lib.git.mirror_pull_project(session, project, debug=debug)
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
    session.remove()
Pierre-Yves Chibon 227f4c
    if debug:
Pierre-Yves Chibon 227f4c
        print('Done')
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
Pierre-Yves Chibon 227f4c
if __name__ == '__main__':
Pierre-Yves Chibon 227f4c
    parser = argparse.ArgumentParser(
Pierre-Yves Chibon 227f4c
            description='Script to send email before the api token expires')
Pierre-Yves Chibon 227f4c
    parser.add_argument(
Pierre-Yves Chibon 227f4c
        '--check', dest='check', action='store_true', default=False,
Pierre-Yves Chibon 227f4c
        help='Print the some output but does not send any email')
Pierre-Yves Chibon 227f4c
    parser.add_argument(
Pierre-Yves Chibon 227f4c
        '--debug', dest='debug', action='store_true', default=False,
Pierre-Yves Chibon 227f4c
        help='Print the debugging output')
Pierre-Yves Chibon 227f4c
    args = parser.parse_args()
Pierre-Yves Chibon 227f4c
    main(debug=args.debug)