コード例 #1
0
ファイル: SynapseLauncher.py プロジェクト: alexena/kalliope
    def start_synapse(cls, name, brain_file=None):
        """
        Start a synapse by it's name
        :param name: Name (Unique ID) of the synapse to launch
        :param brain_file: Brain file path to load instead of the default one
        """
        synapse_name_launch = name
        # get the brain
        if brain_file is None:
            brain = BrainLoader.get_brain()
        else:
            brain = BrainLoader.get_brain(file_path=brain_file)

        # check if we have found and launched the synapse
        synapse_launched = False
        for synapse in brain.synapses:
            if synapse.name == synapse_name_launch:
                cls._run_synapse(synapse)
                synapse_launched = True
                # we found the synapse, we don't need to check the rest of the list
                break

        if not synapse_launched:
            raise SynapseNameNotFound(
                "The synapse name \"%s\" does not exist in the brain file" %
                name)
コード例 #2
0
 def __init__(self, order, main_controller=None, brain_file=None):
     """
     Class used to load brain and run neuron attached to the received order
     :param order: spelt order
     :param main_controller
     :param brain_file: To override the default brain.yml file
     """
     self.main_controller = main_controller
     self.order = order
     if isinstance(self.order, str):
         self.order = order.decode('utf-8')
     if brain_file is None:
         self.brain = BrainLoader.get_brain()
     else:
         self.brain = BrainLoader.get_brain(file_path=brain_file)
     logger.debug("OrderAnalyser, Received order: %s" % self.order)
コード例 #3
0
def main():
    """
    Entry point of Kalliope program
    """
    # create arguments
    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")

    # parse arguments from script parameters
    args = parser.parse_args()

    # require at least one parameter, the action
    if len(sys.argv[1:]) == 0:
        parser.print_usage()
        sys.exit(1)

    # check if we want debug
    configure_logging(debug=args.debug)

    logger.debug("kalliope args: %s" % args)

    # 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 = BrainLoader.get_brain(file_path=brain_file)

    # 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()

    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:
            # first, load events in crontab
            crontab_manager = CrontabManager(brain=brain)
            crontab_manager.load_events_in_crontab()
            Utils.print_success("Events loaded in crontab")
            # then start kalliope
            Utils.print_success("Starting Kalliope")
            Utils.print_info("Press Ctrl+C for stopping")
            # catch signal for killing on Ctrl+C pressed
            signal.signal(signal.SIGINT, signal_handler)
            # start the main controller
            MainController(brain=brain)

    if args.action == "gui":
        ShellGui(brain=brain)
コード例 #4
0
ファイル: FlaskAPI.py プロジェクト: alexena/kalliope
    def __init__(self, app, port=5000, brain_file=None):
        super(FlaskAPI, self).__init__()
        self.app = app
        self.port = port
        self.brain_file = brain_file
        self.brain_yaml = BrainLoader.get_yaml_config(
            file_path=self.brain_file)

        self.app.add_url_rule('/synapses/',
                              view_func=self.get_synapses,
                              methods=['GET'])
        self.app.add_url_rule('/synapses/<synapse_name>',
                              view_func=self.get_synapse,
                              methods=['GET'])
        self.app.add_url_rule('/synapses/<synapse_name>',
                              view_func=self.run_synapse,
                              methods=['POST'])
コード例 #5
0
ファイル: ShellGui.py プロジェクト: alexena/kalliope
    def show_synapses_test_menu(self):
        """
        Show a list of available synapse in the brain to run it directly
        :return:
        """
        # get the list of synapse from the brain
        brain = BrainLoader.get_brain(file_path=self.brain_file)

        # create a tuple for the list menu
        choices = list()
        x = 0
        for el in brain.synapses:
            tup = (str(el.name), str(x))
            choices.append(tup)
            x += 1

        code, tag = self.d.menu("Select a synapse to run", choices=choices)

        if code == self.d.CANCEL:
            self.show_main_menu()
        if code == self.d.OK:
            logger.debug("Run synapse from GUI: %s" % tag)
            SynapseLauncher.start_synapse(tag, brain_file=self.brain_file)
            self.show_synapses_test_menu()
コード例 #6
0
# coding: utf8
import logging

from core.ConfigurationManager.BrainLoader import BrainLoader
from core.ConfigurationManager.SettingLoader import SettingLoader

logging.basicConfig()
logger = logging.getLogger("kalliope")
logger.setLevel(logging.DEBUG)

brain = BrainLoader.get_brain()
print brain.brain_yaml
for synapse in brain.synapses:
    print "test"
    print synapse.name
コード例 #7
0
 def __init__(self, brain_file=None):
     self.my_user_cron = CronTab(user=True)
     self.brain = BrainLoader.get_brain(file_path=brain_file)
     self.base_command = self._get_base_command()