#!/usr/bin/python3

import sys
import argparse
from SystemLib import ogHelp
from ProtocolLib import ogUcastSyntax

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogUcastSyntax', 'ogUcastSyntax params', ['ogUcastSyntax SENDPARTITION      str_sessionSERVER     str_device str_tools str_level', 'ogUcastSyntax RECEIVERPARTITION  str_sessionCLIENT     str_device str_tools str_level', 'ogUcastSyntax SENDFILE           str_sessionSERVER     str_file', 'ogUcastSyntax RECEIVERFILE       str_sessionCLIENT     str_file', 'sessionServer syntax:        portbase:ipCLIENT-1:ipCLIENT-2:ipCLIENT-N', 'sessionServer example:       8000:172.17.36.11:172.17.36.12', 'sessionClient syntax:        portbase:ipMASTER', 'sessionClient example:       8000:172.17.36.249'])
    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 = ogUcastSyntax (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)
