|
@@ -15,6 +15,7 @@ import sys
|
|
|
|
|
|
from kalliope.core.ResourcesManager import ResourcesManager
|
|
|
from kalliope.core.SynapseLauncher import SynapseLauncher
|
|
|
+from kalliope.core.OrderAnalyser import OrderAnalyser
|
|
|
|
|
|
logging.basicConfig()
|
|
|
logger = logging.getLogger("kalliope")
|
|
@@ -22,9 +23,11 @@ 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
|
|
|
+ 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")
|
|
@@ -35,17 +38,20 @@ ACTION_LIST = ["start", "gui", "install"]
|
|
|
|
|
|
|
|
|
def main():
|
|
|
- """
|
|
|
- Entry point of Kalliope program
|
|
|
- """
|
|
|
+ """Entry point of Kalliope program."""
|
|
|
+
|
|
|
# create arguments
|
|
|
parser = argparse.ArgumentParser(description='Kalliope')
|
|
|
parser.add_argument("action", help="[start|gui|install]")
|
|
|
- parser.add_argument("--run-synapse", help="Name of a synapse to load surrounded by quote")
|
|
|
+ parser.add_argument("--run-synapse",
|
|
|
+ help="Name of a synapse to load surrounded by quote")
|
|
|
+ parser.add_argument("--run-order", help="order surrounded by a quote")
|
|
|
parser.add_argument("--brain-file", help="Full path of a brain file")
|
|
|
- parser.add_argument("--debug", action='store_true', help="Show debug output")
|
|
|
+ parser.add_argument("--debug", action='store_true',
|
|
|
+ help="Show debug output")
|
|
|
parser.add_argument("--git-url", help="Git URL of the neuron to install")
|
|
|
- parser.add_argument('-v', '--version', action='version', version='Kalliope ' + version_str)
|
|
|
+ parser.add_argument('-v', '--version', action='version',
|
|
|
+ version='Kalliope ' + version_str)
|
|
|
|
|
|
# parse arguments from script parameters
|
|
|
args = parser.parse_args()
|
|
@@ -60,26 +66,46 @@ def main():
|
|
|
|
|
|
logger.debug("kalliope args: %s" % args)
|
|
|
|
|
|
- # by default, no brain file is set. Use the default one: brain.yml in the root path
|
|
|
+ # by default, no brain file is set.
|
|
|
+ # Use the default one: brain.yml in the root path
|
|
|
brain_file = None
|
|
|
+
|
|
|
# check if user set a brain.yml file
|
|
|
if args.brain_file:
|
|
|
brain_file = args.brain_file
|
|
|
- # load the brain once
|
|
|
- brain_loader = BrainLoader(file_path=brain_file)
|
|
|
- brain = brain_loader.brain
|
|
|
|
|
|
# check the user provide a valid action
|
|
|
if args.action not in ACTION_LIST:
|
|
|
Utils.print_warning("%s is not a recognised action\n" % args.action)
|
|
|
parser.print_help()
|
|
|
|
|
|
+ # install modules
|
|
|
+ if args.action == "install":
|
|
|
+ if not args.git_url:
|
|
|
+ Utils.print_danger("You must specify the git url")
|
|
|
+ else:
|
|
|
+ parameters = {
|
|
|
+ "git_url": args.git_url
|
|
|
+ }
|
|
|
+ res_manager = ResourcesManager(**parameters)
|
|
|
+ res_manager.install()
|
|
|
+ return
|
|
|
+
|
|
|
+ # load the brain once
|
|
|
+ brain_loader = BrainLoader(file_path=brain_file)
|
|
|
+ brain = brain_loader.brain
|
|
|
+
|
|
|
if args.action == "start":
|
|
|
+
|
|
|
# user set a synapse to start
|
|
|
if args.run_synapse is not None:
|
|
|
SynapseLauncher.start_synapse(args.run_synapse, brain=brain)
|
|
|
|
|
|
- if args.run_synapse is None:
|
|
|
+ if args.run_order is not None:
|
|
|
+ order_analyser = OrderAnalyser(args.run_order, brain=brain)
|
|
|
+ order_analyser.start()
|
|
|
+
|
|
|
+ if (args.run_synapse is None) and (args.run_order is None):
|
|
|
# first, load events in event manager
|
|
|
EventManager(brain.synapses)
|
|
|
Utils.print_success("Events loaded")
|
|
@@ -94,21 +120,13 @@ def main():
|
|
|
if args.action == "gui":
|
|
|
ShellGui(brain=brain)
|
|
|
|
|
|
- if args.action == "install":
|
|
|
- if not args.git_url:
|
|
|
- Utils.print_danger("You must specify the git url")
|
|
|
- else:
|
|
|
- parameters = {
|
|
|
- "git_url": args.git_url
|
|
|
- }
|
|
|
- res_manager = ResourcesManager(**parameters)
|
|
|
- res_manager.install()
|
|
|
-
|
|
|
|
|
|
def configure_logging(debug=None):
|
|
|
"""
|
|
|
- Prepare log folder in current home directory
|
|
|
+ Prepare log folder in current home directory.
|
|
|
+
|
|
|
:param debug: If true, set the lof level to debug
|
|
|
+
|
|
|
"""
|
|
|
logger = logging.getLogger("kalliope")
|
|
|
logger.propagate = False
|