Procházet zdrojové kódy

add neuron to launch a script

nico před 8 roky
rodič
revize
b90c247bbc
6 změnil soubory, kde provedl 28 přidání a 5 odebrání
  1. 3 3
      brain.yml
  2. 6 0
      core/OrderAnalyser.py
  3. 2 1
      neurons/__init__.py
  4. 1 0
      neurons/script/__init__.py
  5. 9 0
      neurons/script/script.py
  6. 7 1
      test.py

+ 3 - 3
brain.yml

@@ -7,10 +7,10 @@
 
   - name: "Run a simple script"
     neurons:
-      - script: /some/local/script.sh --some-arguments 1234
-      - say: "Script launched sir"
+      - script: "/home/nico/test.sh"
+      - say: "Script lancé, monsieur"
     when:
-      - order: "Run script"
+      - order: "lance le script"
 
   - name: "Say local date"
     neurons:

+ 6 - 0
core/OrderAnalyser.py

@@ -55,6 +55,12 @@ class OrderAnalyser:
             return True
 
     def _run_plugin(self, plugin, parameter=None):
+        """
+        Dynamic loading of a module
+        :param plugin: Module name to load
+        :param parameter: Parameter of the module
+        :return:
+        """
         print "Run plugin %s with parameter %s" % (plugin, parameter)
         mod = __import__('neurons', fromlist=[plugin])
         klass = getattr(mod, plugin)

+ 2 - 1
neurons/__init__.py

@@ -1,2 +1,3 @@
 from say import Say
-from systemdate import Systemdate
+from systemdate import Systemdate
+from script import Script

+ 1 - 0
neurons/script/__init__.py

@@ -0,0 +1 @@
+from script import Script

+ 9 - 0
neurons/script/script.py

@@ -0,0 +1,9 @@
+from core import Neurone
+import subprocess
+
+
+class Script(Neurone):
+    def __init__(self, script_path):
+        Neurone.__init__(self)
+        p = subprocess.Popen(script_path, stdout=subprocess.PIPE, shell=True)
+        (output, err) = p.communicate()

+ 7 - 1
test.py

@@ -6,7 +6,13 @@ from core.OrderListener import OrderListener
 #
 # oder.start()
 
-order = "quelle heure est il?"
+# test give hour
+# order = "quelle heure est il?"
+
+# test run script
+order = "lance script jarvis"
+
+
 order_analyser = OrderAnalyser(order)
 
 order_analyser.start()