#!/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 "  Latest source codes will be downloaded from their GitHub"
    print "  named-data repositories (https://github.com/named-data)"
    print "\nOPTIONS:"
    print "  install_ndncxx     - install ndn-cxx (named-data/ndn-cxx)"
    print "  setup_security     - create an identity using ndnsec (/tmp/nfd_integration)"
    print "  install_NFD        - install NFD (named-data/NFD)"
    print "  install_ndntraffic - install ndn-traffic-generator (named-data/ndn-traffic-generator)"
    print "  install_ndntlvping - install ndn-tlv-ping (named-data/ndn-tlv-ping)"
    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_ndntlvping",
                     "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_ndntlvping")
            module = __import__("setup_preparation_folder")
            module.run()
            module = __import__("install_dependencies")
            module.run()
            if "install_ndncxx" in actionList:
                module = __import__("install_ndncxx")
                module.run()
            if "setup_security" in actionList:
                module = __import__("setup_security")
                module.run()
            if "install_NFD" in actionList:
                module = __import__("install_NFD")
                module.run()
            if "install_ndntraffic" in actionList:
                module = __import__("install_ndntraffic")
                module.run()
            if "install_ndntlvping" in actionList:
                module = __import__("install_ndntlvping")
                module.run()
            print ""
        else:
            usage()
    else:
        usage()


if __name__ == "__main__":
    main()
