some cleanup
This commit is contained in:
parent
99b808a0de
commit
222af81bed
11 changed files with 13 additions and 157 deletions
|
|
@ -1 +0,0 @@
|
||||||
from lib import *
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
from config import *
|
|
||||||
from core import *
|
|
||||||
from tasks import *
|
|
||||||
from parsers import *
|
|
||||||
from processors import *
|
|
||||||
from services import *
|
|
||||||
|
|
@ -2,14 +2,12 @@ import re
|
||||||
|
|
||||||
|
|
||||||
class Member:
|
class Member:
|
||||||
def __init__(self, nameid, name="", phone="", comment="", parent="", tasks=None):
|
def __init__(self, id, name="", comment="", tasks=None):
|
||||||
self.id = nameid
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.phone = phone
|
|
||||||
self.tasks = []
|
self.tasks = []
|
||||||
self.add_task(tasks)
|
self.add_task(tasks)
|
||||||
self.comment = comment
|
self.comment = comment
|
||||||
self.parent = parent
|
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
return self.id
|
return self.id
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ class JobInfo:
|
||||||
self.log.d("handle call")
|
self.log.d("handle call")
|
||||||
self.log.d(self.service)
|
self.log.d(self.service)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.service._execute()
|
self.service._execute()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log.d(e)
|
self.log.d(e)
|
||||||
|
|
@ -9,16 +9,7 @@ class Task:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def set_task_type(self, taskType):
|
def set_task_type(self, taskType):
|
||||||
"""
|
self._taskType = taskType
|
||||||
sets the type of this task.
|
|
||||||
|
|
||||||
Be aware! this method can only get called once!
|
|
||||||
|
|
||||||
:param taskType: the type of this task
|
|
||||||
"""
|
|
||||||
if hasattr(self, "_taskType"):
|
|
||||||
raise Exception("taskType is only allowed to set once!")
|
|
||||||
self.taskType = taskType
|
|
||||||
|
|
||||||
def get_task_type(self):
|
def get_task_type(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -26,29 +17,5 @@ class Task:
|
||||||
"""
|
"""
|
||||||
return self._taskType
|
return self._taskType
|
||||||
|
|
||||||
def execute_task(self, msg):
|
def some_other_irrelevant_methods(self):
|
||||||
"""
|
|
||||||
this is the method tasks usually override.
|
|
||||||
It gets called anytime the task should get executed
|
|
||||||
|
|
||||||
default does nothing
|
|
||||||
|
|
||||||
:param msg: the msg for this task
|
|
||||||
"""
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _execute(self, taskType, msg):
|
|
||||||
"""
|
|
||||||
internal method which gets called for any member in a hostgroup.
|
|
||||||
It determines if it has an appropriate type by comparing taskType with get_task_type().
|
|
||||||
Calls execute_task() if the type matches
|
|
||||||
|
|
||||||
:param taskType: the type of the fail which is compared with get_task_type()
|
|
||||||
:param msg: the error message
|
|
||||||
|
|
||||||
:return: True if execute_task() is called succesfully, else False
|
|
||||||
"""
|
|
||||||
if self.get_task_type() == taskType:
|
|
||||||
self.execute_task(msg)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
@ -90,7 +90,6 @@ def main():
|
||||||
jobInfo.set_job(job)
|
jobInfo.set_job(job)
|
||||||
jobInfo.set_logger(log)
|
jobInfo.set_logger(log)
|
||||||
jobs.append(jobInfo)
|
jobs.append(jobInfo)
|
||||||
|
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
(r"/jobs", JoblistHandler, dict(jobs=scheduler.get_jobs()))
|
(r"/jobs", JoblistHandler, dict(jobs=scheduler.get_jobs()))
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
"homer":{
|
"homer":{
|
||||||
"name": "Homer Simpson",
|
"name": "Homer Simpson",
|
||||||
"comment": "Security Inspector",
|
"comment": "Security Inspector",
|
||||||
"tasks": [{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}},
|
"tasks": [
|
||||||
{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}]
|
{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}},
|
||||||
|
{"class":"email", "type": "do", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"periods": {
|
"periods": {
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
__author__ = 'rafael'
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
__author__ = 'rafael'
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
__author__ = 'rafael'
|
|
||||||
|
|
||||||
|
|
||||||
class Dummy(object):
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
self.args = kwargs
|
|
||||||
|
|
||||||
def create(args):
|
|
||||||
return Dummy(**args)
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
import json
|
|
||||||
import imp
|
|
||||||
import os.path as path
|
|
||||||
|
|
||||||
class DummyParent(object):
|
|
||||||
def __init__(self, name=None, argsToReplace=None):
|
|
||||||
self.name = name
|
|
||||||
self.argsToReplace = argsToReplace
|
|
||||||
|
|
||||||
def get_args_to_replace(self):
|
|
||||||
return self.argsToReplace
|
|
||||||
|
|
||||||
|
|
||||||
def _create_raw_Object(jsonDict, msgName, creator):
|
|
||||||
"""
|
|
||||||
creates an Main object from the configuration, but just parses raw data and hands it to the object
|
|
||||||
|
|
||||||
:param jsonDict: the configuration file part as dict
|
|
||||||
:param msgName: name of object for error message
|
|
||||||
:param creator: function pointer which is taking two arguments: identifier of the object and arguments.
|
|
||||||
:should return an object
|
|
||||||
:return: a list of objects returned by creator
|
|
||||||
"""
|
|
||||||
items = []
|
|
||||||
for key, val in jsonDict.items():
|
|
||||||
try:
|
|
||||||
item = creator(key, val)
|
|
||||||
items.append(item)
|
|
||||||
except Exception, e:
|
|
||||||
print "ignoring " + msgName + ": " + key + "! reason:"
|
|
||||||
print e
|
|
||||||
return items
|
|
||||||
|
|
||||||
|
|
||||||
def replace_with_import(objList, items_func):
|
|
||||||
"""
|
|
||||||
replaces configuration dicts with their objects by importing and creating it in the first step.
|
|
||||||
In the second step the original list of json config dicts gets replaced by the loaded objects
|
|
||||||
|
|
||||||
:param objList: the list of objects which is iterated on
|
|
||||||
:param modPart: the folder from the module (i.e tasks, parsers)
|
|
||||||
:param items_func: function to get a pointer on the list of json-config-objects to replace. Takes one argument and
|
|
||||||
should return a list of
|
|
||||||
:param class_check: currently unsupported
|
|
||||||
"""
|
|
||||||
for obj in objList:
|
|
||||||
repl = []
|
|
||||||
items = items_func(obj)
|
|
||||||
for clazzItem in items:
|
|
||||||
try:
|
|
||||||
|
|
||||||
clazz = clazzItem["class"]
|
|
||||||
p = path.join("lib", clazz + ".py")
|
|
||||||
mod = imp.load_source(clazz, p)
|
|
||||||
item = mod.create(clazzItem)
|
|
||||||
repl.append(item)
|
|
||||||
except ImportError, err:
|
|
||||||
print "could not import " + clazz + ": " + str(clazzItem) + "! reason"
|
|
||||||
print str(err)
|
|
||||||
except KeyError, k:
|
|
||||||
print "Key " + str(k) + " not in classItem " + str(clazzItem)
|
|
||||||
except Exception, e:
|
|
||||||
print "Error while replacing class ( " + clazz + " ):" + str(e)
|
|
||||||
|
|
||||||
del items[:]
|
|
||||||
items.extend(repl)
|
|
||||||
|
|
||||||
jsonFile = '''
|
|
||||||
{
|
|
||||||
"tests": {
|
|
||||||
"someDummy": {
|
|
||||||
"argsToReplace":
|
|
||||||
[
|
|
||||||
{"class": "dummy", "args": {"someargs":"ok"}},
|
|
||||||
{"class": "dummy", "args": {"someargs":"blah"}}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
|
|
||||||
jsonDict = json.loads(jsonFile)
|
|
||||||
|
|
||||||
|
|
||||||
creator = lambda name, values: DummyParent(name, **values)
|
|
||||||
dummys = _create_raw_Object(jsonDict["tests"], "DummyParent", creator)
|
|
||||||
|
|
||||||
items_func = lambda dummy: dummy.get_args_to_replace()
|
|
||||||
replace_with_import(dummys, items_func)
|
|
||||||
|
|
||||||
for d in dummys:
|
|
||||||
print d.__dict__
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue