|
@@ -0,0 +1,114 @@
|
|
|
+
|
|
|
+
|
|
|
+import argparse
|
|
|
+import logging
|
|
|
+
|
|
|
+from kalliope.core import ShellGui
|
|
|
+from kalliope.core import Utils
|
|
|
+from kalliope.core.ConfigurationManager.BrainLoader import BrainLoader
|
|
|
+from kalliope.core.CrontabManager import CrontabManager
|
|
|
+from kalliope.core.MainController import MainController
|
|
|
+import signal
|
|
|
+import sys
|
|
|
+
|
|
|
+from kalliope.core.SynapseLauncher import SynapseLauncher
|
|
|
+
|
|
|
+logging.basicConfig()
|
|
|
+logger = logging.getLogger("kalliope")
|
|
|
+
|
|
|
+
|
|
|
+def signal_handler(signal, frame):
|
|
|
+ """
|
|
|
+ Used to catch a keyboard signal like Ctrl+C in order to kill the kalliope program
|
|
|
+ :param signal: signal handler
|
|
|
+ :param frame: execution frame
|
|
|
+ """
|
|
|
+ print "\n"
|
|
|
+ Utils.print_info("Ctrl+C pressed. Killing Kalliope")
|
|
|
+ sys.exit(0)
|
|
|
+
|
|
|
+
|
|
|
+ACTION_LIST = ["start", "gui"]
|
|
|
+
|
|
|
+
|
|
|
+def main():
|
|
|
+ """
|
|
|
+ Entry point of Kalliope program
|
|
|
+ """
|
|
|
+
|
|
|
+ parser = argparse.ArgumentParser(description='Kalliope')
|
|
|
+ parser.add_argument("action", help="[start|gui]")
|
|
|
+ parser.add_argument("--run-synapse", help="Name of a synapse to load surrounded by quote")
|
|
|
+ parser.add_argument("--brain-file", help="Full path of a brain file")
|
|
|
+ parser.add_argument("--debug", action='store_true', help="Show debug output")
|
|
|
+
|
|
|
+
|
|
|
+ args = parser.parse_args()
|
|
|
+
|
|
|
+
|
|
|
+ if len(sys.argv[1:]) == 0:
|
|
|
+ parser.print_usage()
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+
|
|
|
+ configure_logging(debug=args.debug)
|
|
|
+
|
|
|
+ logger.debug("kalliope args: %s" % args)
|
|
|
+
|
|
|
+
|
|
|
+ brain_file = None
|
|
|
+
|
|
|
+ if args.brain_file:
|
|
|
+ brain_file = args.brain_file
|
|
|
+
|
|
|
+ brain_loader = BrainLoader.Instance(file_path=brain_file)
|
|
|
+ brain = brain_loader.brain
|
|
|
+
|
|
|
+
|
|
|
+ if args.action not in ACTION_LIST:
|
|
|
+ Utils.print_warning("%s is not a recognised action\n" % args.action)
|
|
|
+ parser.print_help()
|
|
|
+
|
|
|
+ if args.action == "start":
|
|
|
+
|
|
|
+ if args.run_synapse is not None:
|
|
|
+ SynapseLauncher.start_synapse(args.run_synapse, brain=brain)
|
|
|
+
|
|
|
+ if args.run_synapse is None:
|
|
|
+
|
|
|
+ crontab_manager = CrontabManager(brain=brain)
|
|
|
+ crontab_manager.load_events_in_crontab()
|
|
|
+ Utils.print_success("Events loaded in crontab")
|
|
|
+
|
|
|
+ Utils.print_success("Starting Kalliope")
|
|
|
+ Utils.print_info("Press Ctrl+C for stopping")
|
|
|
+
|
|
|
+ signal.signal(signal.SIGINT, signal_handler)
|
|
|
+
|
|
|
+ MainController(brain=brain)
|
|
|
+
|
|
|
+ if args.action == "gui":
|
|
|
+ ShellGui(brain=brain)
|
|
|
+
|
|
|
+
|
|
|
+def configure_logging(debug=None):
|
|
|
+ """
|
|
|
+ Prepare log folder in current home directory
|
|
|
+ :param debug: If true, set the lof level to debug
|
|
|
+ """
|
|
|
+ logger = logging.getLogger("kalliope")
|
|
|
+ logger.propagate = False
|
|
|
+ ch = logging.StreamHandler()
|
|
|
+ ch.setLevel(logging.DEBUG)
|
|
|
+ formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
|
|
|
+ ch.setFormatter(formatter)
|
|
|
+
|
|
|
+
|
|
|
+ logger.addHandler(ch)
|
|
|
+
|
|
|
+ if debug:
|
|
|
+ logger.setLevel(logging.DEBUG)
|
|
|
+ else:
|
|
|
+ logger.setLevel(logging.INFO)
|
|
|
+
|
|
|
+ logger.debug("Logger ready")
|