#!/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_repo       - install repo-ng (named-data/repo-ng)"
    print "  install_infoedit   - install infoedit"
    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_repo",
                     "install_infoedit",
                     "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_repo")
                actionList.add("install_infoedit")
            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()
            if "install_repo" in actionList:
                module = __import__("install_repo")
                module.run()
            if "install_infoedit" in actionList:
                module = __import__("install_infoedit")
                module.run()
            print ""
        else:
            usage()
    else:
        usage()


if __name__ == "__main__":
    main()
