refactor...

community
Steve L. Nyemba 8 years ago
parent f1b3e8abf2
commit 1aad0c4acc

@ -1,15 +1,18 @@
{
"virtual-env":{
"class":"Sandbox",
"config":{
"3-launchpad":{"requirements":"/Users/steve/Documents/git/repair-file/required.txt","sandbox":"/Users/steve/Documents/git/sandbox"}
}
"id":"zulu-hacker",
"key":"4q-h8r5-247&!570p=[0v8]x360",
"api":"localhost",
"delay":0.5,
"store":{
"class":{"read":"CouchdbReader","write":"CouchdbWriter"},
"args":{"uri":"http://localhost:5984","dbname":"monitor","uid":"logs"}
},
"processes":{
"class":"DetailProcess",
"config":{
"system":["postgresql","couchdb","httpd"]
}
"procs":["kate","firefox"],
"folders":["/home/steve/tmp","/home/steve/git","/home/steve/Downloads"],
"actions":{
"folders":{"threshold":"10mb","action":"archive"},
"apps":{"firefox":"","kate":"" }
}
}

@ -60,8 +60,11 @@ class Actor(Thread):
class Folders(Actor):
def init(self,config,item):
Actor.init(self,config,item)
self.config = config['folders']
self.item = item
self.lfolders = config['folders']
self.config = config['actions']['folders']
self.threshold = self.get_size(self.config['threshold'])
self.item = item
def archive(self,item):
"""
This function will archive all files in a given folder
@ -82,13 +85,44 @@ class Folders(Actor):
"""
This function consists in deleting files from a given folder
"""
shutil.rmtree(item['label'])
os.mkdir(item['label'])
rpath = item['label']
lists = os.listdir(item['label'])
for name in list() :
path = os.sep([item['label'],name])
if os.path.isdir(path) :
shutil.rmtree(path)
else:
os.remove(path)
#
#
def get_size(self,value):
units = {'MB':1000,'GB':1000000,'TB':1000000000} # converting to kb
key = set(unites) & set(re.split('(\d+)',value.upper()))
if len(key) == 0:
return -1
key = key.pop()
return float(value.upper().replace('MB','').strip()) * units[key]
def isvalid(self,item):
return os.path.exists(item['label'])
"""
This function returns whether the following :
p : folder exists
q : has_reached threashold
"""
p = os.path.exists(item['label']) and item['label'] in self.lfolders
q = self.get_size(item['size']) >= self.threshold
return p and q
def process(self,item):
print item
if self.isValid(item) :
name = self.config['action']
stream = "".join([name,'(',json.dumps(item),')'])
eval(stream)
class Kill(Actor):
@ -109,7 +143,7 @@ class Start(Actor):
def init(self,config,item):
Actor.init(self,config,item)
self.config = config['start']
self.config = config['apps']
self.ng = ng(self.config.keys())
def isValid(self,name):
@ -169,7 +203,10 @@ class Apps(Actor):
self.reboot()
class Event(Thread):
def __init__(self,config):
pass
def run(self):
"""
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
@ -187,6 +224,7 @@ class Orchestrator(Actor):
f.close()
self.config = config
Actor.__init__(self)
self.actors = {"apps":Apps(),"folders":Folders()}
self.is_master_node = False
self.items = []

Loading…
Cancel
Save