#!/usr/bin/python2
import os
import sys
import inspect
from sets import Set

def usage():
    print "\nUSAGE:"
    print "  ./install_apps.py [OPTIONS]\n"
    print "  Install NDN applications"
    print "  By default, the latest version of each package will be downloaded from the NDN GitHub"
    print "  repositories (https://github.com/named-data). To obtain the packages locally or from"
    print "  a specific branch or Gerrit change, use the repos.conf file (see repos.conf.sample for"
    print "  more information)."
    print "\nOPTIONS:"
    print "  install_ndncxx     - install ndn-cxx (named-data/ndn-cxx)"
    print "  setup_security     - create an identity using ndnsec (/tmp/nfd_integration_tests)"
    print "  install_NFD        - install NFD (named-data/NFD)"
    print "  install_ndntraffic - install ndn-traffic-generator (named-data/ndn-traffic-generator)"
    print "  install_ndntools   - install ndn-tools (named-data/ndn-tools)"
    print "  install_repong     - install repo-ng (named-data/repo-ng)"
    print "  install_infoedit   - install infoedit"
    print "  install_tools      - install test tools"
    print "  install_all        - do all of the above"
    print "  help               - print this message and exit\n"


def main():
    cmd_subfolder = os.path.realpath(
        os.path.abspath(os.path.join(os.path.split(
            inspect.getfile(inspect.currentframe()))[0], "install_helpers")))
    if cmd_subfolder not in sys.path:
        sys.path.insert(0, cmd_subfolder)
    validOptions = [ "install_ndncxx",
                     "setup_security",
                     "install_NFD",
                     "install_ndntraffic",
                     "install_ndntools",
                     "install_repong",
                     "install_infoedit",
                     "install_tools",
                     "install_all",
                     "help" ]

    if len(sys.argv) > 1:
        actionList = Set(sys.argv[1:])
        optionsStatus = 0
        for option in actionList:
            if option not in validOptions:
                print "Invalid option provided - " + option
                optionsStatus = -1
                break
        if optionsStatus == 0 and "help" not in actionList:
            if "install_all" in actionList:
                actionList.add("install_ndncxx")
                actionList.add("setup_security")
                actionList.add("install_NFD")
                actionList.add("install_ndntraffic")
                actionList.add("install_ndntools")
                actionList.add("install_repong")
                actionList.add("install_infoedit")
                actionList.add("install_tools")
            os.system("./install_helpers/setup_preparation_folder.sh")
            os.system("./install_helpers/install_dependencies.sh")
            if "install_ndncxx" in actionList:
                os.system("./install_helpers/install_ndncxx.sh")
            if "setup_security" in actionList:
                os.system("./install_helpers/setup_security.sh")
            if "install_NFD" in actionList:
                os.system("./install_helpers/install_NFD.sh")
            if "install_ndntraffic" in actionList:
                os.system("./install_helpers/install_ndntraffic.sh")
            if "install_ndntools" in actionList:
                os.system("./install_helpers/install_ndntools.sh")
            if "install_repong" in actionList:
                os.system("./install_helpers/install_repong.sh")
            if "install_infoedit" in actionList:
                os.system("./install_helpers/install_infoedit.sh")
            if "install_tools" in actionList:
                module = __import__("install_tools")
                module.run()
            print ""
        else:
            usage()
    else:
        usage()


if __name__ == "__main__":
    main()
