#!/usr/bin/python3

import sys
import argparse
from SystemLib import ogHelp
from ProtocolLib import ogTorrentStart

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogTorrentStart', 'ogTorrentStart [ str_repo] [ [Relative_path_fileTORRENT] | [str_REPOSITORY path_fileTORRENT] |  [int_ndisk int_npart path_fileTORRENT ]  ] SessionTorrent', ['ogTorrentStart CACHE /PS1_PH1.img.torrent seeder:10000', 'ogTorrentStart /opt/opengnsys/cache/linux.iso peer:60', 'ogTorrentStart 1 1 /linux.iso.torrent leecher:60'])
    sys.exit (0)

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

args = parser.parse_args()

if 3 == len (sys.argv):
    ret = ogTorrentStart (torrentfile=args.torrentfile, torrentsess=args.torrentsess)
elif 4 == len (sys.argv):
    ret = ogTorrentStart (container=args.container, torrentfile=args.torrentfile, torrentsess=args.torrentsess)
elif 5 == len (sys.argv):
    ret = ogTorrentStart (disk=args.disk, par=args.par, torrentfile=args.torrentfile, torrentsess=args.torrentsess)

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