#!/usr/bin/python3

import sys
import argparse
from SystemLib import ogHelp
from ProtocolLib import ogCreateTorrent

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogCreateTorrent', 'ogCreateTorrent [str_REPOSITORY] [int_ndisk int_npart] Relative_path_file IpBttrack', ['ogCreateTorrent 1 1 /aula1/winxp 10.1.15.23', 'ogCreateTorrent REPO /aula1/winxp 10.1.15.45'])
    sys.exit (0)

parser = argparse.ArgumentParser (add_help=False)
if 4 == len (sys.argv):
    parser.add_argument ('container')
elif 5 == len (sys.argv):
    parser.add_argument ('disk')
    parser.add_argument ('par')

parser.add_argument ('file')
parser.add_argument ('ip_bttrack')
args = parser.parse_args()

if 4 == len (sys.argv):
    ret = ogCreateTorrent (container=args.container, file=args.file, ip_bttrack=args.ip_bttrack)
elif 5 == len (sys.argv):
    ret = ogCreateTorrent (disk=args.disk, par=args.par, file=args.file, ip_bttrack=args.ip_bttrack)
if ret is not None:
    if   ret == True: sys.exit (0)
    elif ret == False: sys.exit (1)
    else: print (ret)
