Folder handling archive and delete

community
Steve L. Nyemba 8 years ago
parent 21901ddac5
commit f9ae55dd03

@ -13,6 +13,7 @@
import json import json
from threading import Thread from threading import Thread
import os import os
import zipfile
import subprocess import subprocess
from monitor import ProcessCounter from monitor import ProcessCounter
from utils.transport import QueueListener, QueueWriter, QueueReader from utils.transport import QueueListener, QueueWriter, QueueReader
@ -52,13 +53,38 @@ class Actor(Thread):
""" """
def post(self,**args): def post(self,**args):
pass pass
"""
This is designed to handle folders i.e cleaning/archiving the folders
"""
class Folders(Actor): class Folders(Actor):
def init(self,config,item): def init(self,config,item):
Actor.init(self,config,item) Actor.init(self,config,item)
self.config = config['folders'] self.config = config['folders']
self.item = item self.item = item
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): def isvalid(self,item):
print self.conf return os.path.exists(item['label'])
def process(self,item): def process(self,item):
print item print item
@ -123,19 +149,25 @@ class Apps(Actor):
self.crashes.append(row) self.crashes.append(row)
else: else:
self.running.append(row) self.running.append(row)
def reboot(self):
def process(self,rows): for row_run in self.running:
#rows = [row for row in rows if row['status'] == 'crash'] : pass
self.classify(rows) def start(self):
#handler = Start()
#handler.init(self.config)
#[handler.process(row_crash) for row_crash in self.crashes ]
for row_crash in self.crashes: for row_crash in self.crashes:
thread = Start() thread = Start()
thread.init(self.config,row_crash) thread.init(self.config,row_crash)
thread.daemon = True thread.daemon = True
thread.start() 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 The orchestrator class is designed to aggregate actions and communicate back to the caller
Mesage passing is structured as follows {from,to,content} The content is designed to be understood by the actor Mesage passing is structured as follows {from,to,content} The content is designed to be understood by the actor

@ -91,7 +91,7 @@ class ICollector(Thread) :
row = data row = data
# #
# At this point we should check for the status and if it prompts an action # 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 # - submit the row to Event for analysis
# - The event orchestrator will handle things from this point on # - The event orchestrator will handle things from this point on
# #

Loading…
Cancel
Save