#!/usr/bin/env python

# oio-rawx-crawler
# Copyright (C) 2021 OVH SAS
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


from oio.common.green import eventlet_monkey_patch
eventlet_monkey_patch()

import argparse
from oio.crawler.rawx.crawler import RawxCrawler
from oio.common.daemon import run_daemon


def make_arg_parser():
    descr = """
        Periodically runs configured pipelines.
    """
    parser = argparse.ArgumentParser(description=descr)
    parser.add_argument(
        'config',
        help="""
        A file containing an oio-rawx-crawler configuration file.
        Any arguments passed alongside a configuration file will be ignored.
        """)
    parser.add_argument(
        '--verbose', '-v',
        action='store_true',
        help="More verbose output")
    return parser


if __name__ == '__main__':
    args = make_arg_parser().parse_args()
    verbose = args.verbose
    config = args.config

    run_daemon(RawxCrawler, conf_file=config, section_name='rawx-crawler',
               verbose=verbose)
