#!/usr/bin/env python
# Copyright European Organization for Nuclear Research (CERN)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Authors:
# - Mario Lassnig, <mario.lassnig@cern.ch>, 2013-2015

"""
ConveyorInjector is a daemon to queue file transfers for testing purposes.
"""

import argparse
import signal

from rucio.daemons.mock.conveyorinjector import run, stop

if __name__ == "__main__":

    signal.signal(signal.SIGTERM, stop)

    parser = argparse.ArgumentParser()
    parser.add_argument("--src", action="store", default=None, help='(scheme or token)://host:port/path')
    parser.add_argument("--dst", action="store", default=None, help='(scheme or token)://host:port/path')
    parser.add_argument("--upload", action="store_true", default=False, help='Upload a file to source')
    parser.add_argument("--same-src", action="store_true", default=False, help='Keep the same source')
    parser.add_argument("--same-dst", action="store_true", default=False, help='Keep the same destination')
    parser.add_argument("--loop", action="store", default=1, help='Number of requests to inject')
    args = parser.parse_args()

    try:
        run(loop=int(args.loop),
            src=args.src,
            dst=args.dst,
            upload=args.upload,
            same_src=args.same_src,
            same_dst=args.same_dst)
    except KeyboardInterrupt:
        stop()
