Browse Source

add cron test class

nico 8 years ago
parent
commit
1dc7bdc4f3
3 changed files with 36 additions and 3 deletions
  1. 1 0
      Docs/dev_env_install.md
  2. 34 2
      test.py
  3. 1 1
      test.yml

+ 1 - 0
Docs/dev_env_install.md

@@ -25,6 +25,7 @@ pip install ansible
 pip install pygame
 pip install python2-pythondialog
 pip install jinja
+pip install python-crontab
 ```
 
 ### Test your env

+ 34 - 2
test.py

@@ -1,4 +1,6 @@
 # coding=utf-8
+from crontab import CronTab
+
 from core import ConfigurationManager
 from core.NeuroneLauncher import NeuroneLauncher
 from core.OrderAnalyser import OrderAnalyser
@@ -8,11 +10,41 @@ from neurons.ansible_tasks.ansible_tasks import Ansible_tasks
 import logging
 
 from core import ShellGui
+from crontab import CronSlices
+
+# oa = OrderAnalyser("dis bonjour", brain_file="test.yml")
+#
+# oa.start()
+from crontab import CronSlices
+
+class CronManager:
+
+    def __init__(self):
+        """
+        Manager the crontab to add JAVIS event
+        """
+        self.my_user_cron = CronTab(user=True)
+        # my_user_cron.remove_all()
+        self.command = "cat test > /home/nico/Desktop/test.txt"
 
+    def add_event(self, period_string, event_id):
 
-oa = OrderAnalyser("dis bonjour", brain_file="test.yml")
+        job = self.my_user_cron.new(command='self.command', comment='JARVIS')
+        if CronSlices.is_valid(period_string):
+            job.setall(period_string)
+            job.enable()
+            self.my_user_cron.write()
 
-oa.start()
+    def get_jobs(self):
+        for job in self.my_user_cron:
+                print job
 
+    def _remove_all_jarvis_job(self):
+        pass
 
 
+# test
+cron_manager = CronManager()
+period_string = "* * 5 5 *"
+event_id = 1
+cron_manager.add_event(period_string=period_string, event_id=event_id)

+ 1 - 1
test.yml

@@ -4,5 +4,5 @@
       - say:
           message: "Script lancé, monsieur"
     when:
-      - order: "dis bonjour"
+      - event: "* * 5 5 *"