Browse Source

Folder handling archive and delete

steve 8 năm trước cách đây
mục cha
commit
f9ae55dd03
2 tập tin đã thay đổi với 42 bổ sung10 xóa
  1. 41 9
      src/utils/agents/actor.py
  2. 1 1
      src/utils/agents/data-collector.py

+ 41 - 9
src/utils/agents/actor.py

@@ -13,6 +13,7 @@
 import json
 from threading import Thread
 import os
+import zipfile
 import subprocess
 from monitor import ProcessCounter
 from utils.transport import QueueListener, QueueWriter, QueueReader
@@ -52,13 +53,38 @@ class Actor(Thread):
     """
     def post(self,**args):
         pass
+"""
+    This is designed to handle folders i.e cleaning/archiving the folders
+    
+"""
 class Folders(Actor):
     def init(self,config,item):
         Actor.init(self,config,item)
         self.config = config['folders']
         self.item   = item
-    def isvalid(self,item):
-        print self.conf
+    def archive(self,item):
+    """
+        This function will archive all files in a given folder
+        @pre : isValid
+    """
+        folder = item['label']
+        signature='-'.join([str(item['date']),str(item['count']),'-files'])
+        tarball=os.sep([folder,signature])
+        shutil.make_archive(tarball,'tar',folder)
+        self.clean(item)
+        #
+        # @TODO: The archive can be uploaded to the cloud or else where
+        #   - This allows the submission of data to a processing engine if there ever were one
+        #
+        pass
+    
+    def clean(self,item):
+    """
+        This function consists in deleting files from a given folder
+    """
+        pass
+    def isvalid(self,item):        
+        return os.path.exists(item['label'])
     def process(self,item):
         print item
         
@@ -123,18 +149,24 @@ class Apps(Actor):
                 self.crashes.append(row)
             else:
                 self.running.append(row)
-    
-    def process(self,rows):
-        #rows = [row for row in rows if row['status'] == 'crash'] :
-        self.classify(rows)
-        #handler = Start()
-        #handler.init(self.config)
-        #[handler.process(row_crash) for row_crash in self.crashes ]
+    def reboot(self):
+        for row_run in self.running:
+            pass
+    def start(self):
         for row_crash in self.crashes:
             thread = Start()
             thread.init(self.config,row_crash)
             thread.daemon = True
             thread.start()
+        
+    def process(self,rows):
+        self.classify(rows)
+        if self.crashes :
+            self.start()
+        if self.running:
+            self.reboot()
+        
+        
             
 """
     The orchestrator class is designed to aggregate actions and communicate back to the caller

+ 1 - 1
src/utils/agents/data-collector.py

@@ -91,7 +91,7 @@ class ICollector(Thread) :
 					row = data
 				#
 				# At this point we should check for the status and if it prompts an action
-				# @TODO Use a design pattern for this ...
+				# @TODO Use a design pattern for this ... (Aggregation?)
 				#   - submit the row to Event for analysis
 				#   - The event orchestrator will handle things from this point on
 				#