#!/usr/bin/python3

import sys
import argparse
from SystemLib import ogHelp
from ProtocolLib import ogMcastReceiverFile

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogMcastReceiverFile', 'ogMcastReceiverFile [ str_portMcast] [ [Relative_path_file] | [str_REPOSITORY path_file] |  [int_ndisk int_npart path_file ]  ]', ['ogMcastReceiverFile 9000 /PS1_PH1.img', 'ogMcastReceiverFile 9000 CACHE /aula1/PS2_PH4.img', 'ogMcastReceiverFile 9000 1 1 /isos/linux.iso'])
    sys.exit (0)

parser = argparse.ArgumentParser (add_help=False)
if 3  == len (sys.argv):
    parser.add_argument ('sess', nargs='?', default=None)
    parser.add_argument ('file', nargs='?', default=None)
elif 4  == len (sys.argv):
    parser.add_argument ('sess', nargs='?', default=None)
    parser.add_argument ('container', nargs='?', default=None)
    parser.add_argument ('file', nargs='?', default=None)
elif 5  == len (sys.argv):
    parser.add_argument ('sess', nargs='?', default=None)
    parser.add_argument ('disk', nargs='?', default=None)
    parser.add_argument ('par', nargs='?', default=None)
    parser.add_argument ('file', nargs='?', default=None)

args = parser.parse_args()

if 3  == len (sys.argv):
    ret = ogMcastReceiverFile (file=args.file, sess=args.sess)
elif 4  == len (sys.argv):
    ret = ogMcastReceiverFile (container=args.container, file=args.file, sess=args.sess)
elif 5  == len (sys.argv):
    ret = ogMcastReceiverFile (disk=args.disk, par=args.par, file=args.file, sess=args.sess)

if ret is not None:
    if   ret == True: sys.exit (0)
    elif ret == False: sys.exit (1)
    else: print (ret)
