#!/usr/bin/python3

import sys
import argparse
from SystemLib import ogHelp
from ProtocolLib import ogMcastSyntax

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogMcastSyntax', 'ogMcastSyntax params', ['ogMcastSyntax SENDPARTITION      str_sessionSERVER     str_device str_tools str_level', 'ogMcastSyntax RECEIVERPARTITION  str_sessionCLIENT     str_device str_tools str_level', 'ogMcastSyntax SENDFILE           str_sessionSERVER     str_file', 'ogMcastSyntax RECEIVERFILE       str_sessionCLIENT     str_file', 'sessionServer syntax:        portbase:method:mcastaddress:speed:nclients:ntimeWaitingUntilNclients', 'sessionServer example:       9000:full-duplex|half-duplex|broadcast:239.194.17.36:80M:50:60', 'sessionClient syntax:        portbase', 'sessionClient example:       9000', 'sessionClient syntax:        portbase:serverIP:TimeOut_session:TimeOut_transmision', 'sessionClient example:       9000:172.17.88.161:40:120'])
    sys.exit (0)

kwargs = {}
parser = argparse.ArgumentParser (add_help=False)
if 'SENDPARTITION' == sys.argv[1] or 'RECEIVERPARTITION' == sys.argv[1]:
    parser.add_argument ('op')
    parser.add_argument ('sess')
    parser.add_argument ('device')
    parser.add_argument ('tool')
    parser.add_argument ('level')
    args = parser.parse_args()
    kwargs = { 'device': args.device, 'tool': args.tool, 'level': args.level }
elif 'SENDFILE' == sys.argv[1] or 'RECEIVERFILE' == sys.argv[1]:
    parser.add_argument ('op')
    parser.add_argument ('sess')
    parser.add_argument ('file')
    args = parser.parse_args()
    kwargs = { 'file': args.file }

ret = ogMcastSyntax (args.op, args.sess, **kwargs)
if ret is not None:
    if   ret == True: sys.exit (0)
    elif ret == False: sys.exit (1)
    else: print (ret)
