Преглед на файлове

event does not need an ID anymore. We will use the name of the synapse as unique ID

Nicolas Marcq преди 10 години
родител
ревизия
7806609c84
променени са 7 файла, в които са добавени 36 реда и са изтрити 27 реда
  1. 1 1
      core/ConfigurationManager/BrainLoader.py
  2. 2 2
      core/ConfigurationManager/ConfigurationChecker.py
  3. 2 2
      core/CrontabManager.py
  4. 3 5
      core/Models/Event.py
  5. 12 6
      jarvis.py
  6. 13 3
      test.py
  7. 3 8
      test.yml

+ 1 - 1
core/ConfigurationManager/BrainLoader.py

@@ -95,7 +95,7 @@ class BrainLoader(YAMLLoader):
             # print "is event"
             event = signal_or_event_dict["event"]
             if ConfigurationChecker.check_event_dict(event):
-                return Event(identifier=event["id"], period=event["period"])
+                return Event(period=event["period"])
 
         if 'order' in signal_or_event_dict:
             order = signal_or_event_dict["order"]

+ 2 - 2
core/ConfigurationManager/ConfigurationChecker.py

@@ -54,8 +54,8 @@ class ConfigurationChecker:
 
     @staticmethod
     def check_event_dict(event_dict):
-        if 'id' not in event_dict:
-            raise NoEventID("Event must contain a unique ID: %s" % event_dict)
+        # if 'id' not in event_dict:
+        #     raise NoEventID("Event must contain a unique ID: %s" % event_dict)
         if 'period' not in event_dict:
             raise NoEventPeriod("Event must contain a period: %s" % event_dict)
 

+ 2 - 2
core/CrontabManager.py

@@ -34,11 +34,11 @@ class CrontabManager:
                 # if the signal is an event we add it to the crontab
                 if type(signal) == Event:
                     # for all synapse with an event, we add the task id to the crontab
-                    self._add_event(period_string=signal.period, event_id=signal.identifier)
+                    self._add_event(period_string=signal.period, event_id=synapse.name)
 
     def _add_event(self, period_string, event_id):
         my_user_cron = CronTab(user=True)
-        job = my_user_cron.new(command=self.base_command+" "+str(event_id), comment=CRONTAB_COMMENT)
+        job = my_user_cron.new(command=self.base_command+" "+str("\""+ event_id + "\""), comment=CRONTAB_COMMENT)
         if CronSlices.is_valid(period_string):
             job.setall(period_string)
             job.enable()

+ 3 - 5
core/Models/Event.py

@@ -1,9 +1,7 @@
 class Event(object):
-    def __init__(self, identifier, period):
-        self.identifier = identifier
+    def __init__(self, period):
         self.period = period
 
     def __str__(self):
-        return "%s: Id: %s, period: %s" % (self.__class__.__name__,
-                                           self.identifier,
-                                           self.period)
+        return "%s: period: %s" % (self.__class__.__name__,
+                                   self.period)

+ 12 - 6
jarvis.py

@@ -20,6 +20,7 @@ def main():
     # create arguments
     parser = argparse.ArgumentParser(description='JARVIS')
     parser.add_argument("action", help="[start|gui]")
+    parser.add_argument("--synapse", help="SYNAPSE")
 
     # parse arguments from script parameters
     args = parser.parse_args()
@@ -28,12 +29,17 @@ def main():
         sys.exit(1)
 
     if args.action == "start":
-        print "Starting JARVIS. Press Ctrl+C for stopping"
-        # catch signal for killing on Ctrl+C pressed
-        signal.signal(signal.SIGINT, signal_handler)
-        # start the main controller
-        main_controller = MainController()
-        main_controller.start()
+        # user set a synapse to start
+        if args.synapse is not None:
+            print "Playing synapse: %s" % args.synapse
+
+        if args.synapse is None:
+            print "Starting JARVIS. Press Ctrl+C for stopping"
+            # catch signal for killing on Ctrl+C pressed
+            signal.signal(signal.SIGINT, signal_handler)
+            # start the main controller
+            main_controller = MainController()
+            main_controller.start()
 
     if args.action == "gui":
         ShellGui()

+ 13 - 3
test.py

@@ -1,4 +1,7 @@
 # coding=utf-8
+import os
+
+from core.CrontabManager import CrontabManager
 from core.OrderAnalyser import OrderAnalyser
 
 import logging
@@ -6,8 +9,15 @@ logger = logging.getLogger()
 logger.setLevel(logging.DEBUG)
 
 
-# oa = OrderAnalyser("test", brain_file="brain_examples/fr/say_examples.yml")
+# # oa = OrderAnalyser("test", brain_file="brain_examples/fr/say_examples.yml")
+#
+# oa = OrderAnalyser("test", brain_file="brain_examples/fr/fr_systemdate.yml")
+#
+# oa.start()
 
-oa = OrderAnalyser("test", brain_file="brain_examples/fr/fr_systemdate.yml")
+# cmd = "python jarvis.py start --synapse \"this is my synapse\""
+#
+# os.system(cmd)
 
-oa.start()
+crontab_manager = CrontabManager(brain_file="test.yml")
+crontab_manager.load_events_in_crontab()

+ 3 - 8
test.yml

@@ -1,14 +1,9 @@
 ---
-  - name: "Say hello"
+  - name: "say hello"
     neurons:
       - say:
           message:
             - "Bonjour monsieur"
-            - "Bonjour maitre"
-      - sleep:
-          seconds: 1
-      - say:
-          message: "Je suis Jarvice"
-          tts: "voxygen"
     signals:
-      - order: "dis bonjour"
+      - event:
+          period: "* * * 5 *"