#!/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_ndntools   - install ndn-tools (named-data/ndn-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_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")
            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_ndntools" in actionList:
                module = __import__("install_ndntools")
                module.run()
            print ""
        else:
            usage()
    else:
        usage()


if __name__ == "__main__":
    main()
