Pārlūkot izejas kodu

Merged branch dev into dev_nico

nico 8 gadi atpakaļ
vecāks
revīzija
424f33227d

+ 9 - 0
Docs/kalliope_cli.md

@@ -72,6 +72,15 @@ Example of use
 kalliope start --run-synapse "say-hello"
 ```
 
+### --run-order "Your Order"
+
+Run a specific order from command line.
+
+Example of use
+```bash
+kalliope start --run-order "hello"
+```
+
 ### --brain-file BRAIN_FILE
 
 Replace the default brain file from the root of the project folder by a custom one.

+ 13 - 4
Docs/neuron_list.md

@@ -20,16 +20,25 @@ A neuron is a module that will perform some actions attached to an order. You ca
 
 | Name                                                                                 | Description                                                                             |
 |--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
-| [gmail_checker](https://github.com/kalliope-project/kalliope_neuron_gmail)           | Get the number of unread email and their subjects from a gmail account                  |
-| [hue](https://github.com/kalliope-project/kalliope_neuron_hue)                       | Control the Philips Hue lighting system                                                 |
+| [facebook](https://github.com/kalliope-project/kalliope_neuron_facebook)             | Post and Read message on Facebook                                                        |
+| [gmail_checker](https://github.com/kalliope-project/kalliope_neuron_gmail)           | Get the number of unread email and their subjects from a gmail account             |
+| [google agenda](https://github.com/bacardi55/kalliope-google-calendar)               | Get your next meetings on google calendar                                               |
+| [hue](https://github.com/kalliope-project/kalliope_neuron_hue)                       | Control the Philips Hue lighting system  |
+| [list available orders](https://github.com/bacardi55/kalliope-list-available-orders) | Let kalliope tell you what she how she can help                                         |
+| [MPD](https://github.com/bacardi55/kalliope-mpd)                                     | Play music via an MPD server                                                            |
 | [openweathermap](https://github.com/kalliope-project/kalliope_neuron_openweathermap) | Get the weather of a location                                                           |
+| [pi camera](https://github.com/bacardi55/kalliope-picamera)                          | Take picture with your picamera                                                         |
 | [pushetta](https://github.com/kalliope-project/kalliope_neuron_pushetta)             | Send a push message to a remote device like Android/iOS/Windows Phone or Chrome browser |
-| [rss_reader](https://github.com/kalliope-project/kalliope_neuron_rss_reader)         | get rss feed from website                                                               |
+| [repeat](https://github.com/bacardi55/kalliope-repeat)                               | Make kalliope say whatever you want                                                     |
+| [rss_reader](https://github.com/kalliope-project/kalliope_neuron_rss_reader)         | Get rss feed from website                                                               |
+| [slack](https://github.com/kalliope-project/kalliope_neuron_slack)                   | Post and Read message on Slack                                                          |
+| [system_status](https://github.com/bacardi55/kalliope-system-status)                 | Get info about the system (cpu, memory, …                                                               |
 | [tasker](https://github.com/kalliope-project/kalliope_neuron_tasker)                 | Send a message to Android tasker app                                                    |
 | [twitter](https://github.com/kalliope-project/kalliope_neuron_twitter)               | Send a Twit from kalliope                                                               |
 | [wake_on_lan](https://github.com/kalliope-project/kalliope_neuron_wake_on_lan)       | Wake on lan a computer                                                                  |
+| [web scraper](https://github.com/bacardi55/kalliope-web-scraper)                     | Read web pages that don't provide RSS feed or APIs (by scraping html)                   |                            |
 | [wikipedia](https://github.com/kalliope-project/kalliope_neuron_wikipedia)           | Search for a page on Wikipedia                                                          |
-| [slack](https://github.com/kalliope-project/kalliope_neuron_slack)                   | Post and Read message on Slack                                                          |
+
 
 Wanna add your neuron in the list? Open [an issue](../../issues) with the link of your neuron or send a pull request to update the list directly.
 

+ 41 - 23
kalliope/__init__.py

@@ -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

+ 5 - 3
kalliope/core/ResourcesManager.py

@@ -3,6 +3,7 @@ import logging
 import os
 import shutil
 import re
+import tempfile
 
 from git import Repo
 from packaging import version
@@ -17,7 +18,7 @@ logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
 # Global values for processing:
-LOCAL_TMP_FOLDER = "/tmp/kalliope/resources/"
+# LOCAL_TMP_FOLDER = "/tmp/kalliope/resources/"
 TMP_GIT_FOLDER = "kalliope_new_module_temp_name"
 DNA_FILE_NAME = "dna.yml"
 INSTALL_FILE_NAME = "install.yml"
@@ -53,7 +54,8 @@ class ResourcesManager(object):
         self.git_url = kwargs.get('git_url', None)
 
         # temp path where we install the new module
-        self.tmp_path = LOCAL_TMP_FOLDER + TMP_GIT_FOLDER
+        self.tmp_path = tempfile.gettempdir() + "/kalliope/resources/" +\
+                TMP_GIT_FOLDER
         self.dna_file_path = self.tmp_path + os.sep + DNA_FILE_NAME
         self.install_file_path = self.tmp_path + os.sep + INSTALL_FILE_NAME
         self.dna = None
@@ -214,7 +216,7 @@ class ResourcesManager(object):
         logger.debug("[ResourcesManager] Rename temp folder")
         new_absolute_neuron_path = target_folder + os.sep + name
         try:
-            os.rename(tmp_path, new_absolute_neuron_path)
+            shutil.move(tmp_path, new_absolute_neuron_path)
             return new_absolute_neuron_path
         except OSError:
             # the folder already exist

+ 1 - 0
kalliope/neurons/sleep/sleep.py

@@ -21,3 +21,4 @@ class Sleep(NeuronModule):
         """
         if self.seconds is None:
             raise MissingParameterException("You must set a number of seconds as parameter")
+        return True