From 72354b4ed410d9cb2b06af08f6c27f93f5abb8c4 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 19 Jun 2013 03:26:25 +0200 Subject: [PATCH] whitespaces at night... --- lib/config/hostgroups.py | 5 +++-- lib/config/parser.py | 26 +++++++++++--------------- lib/core/command.py | 1 + lib/core/linspector_daemon.py | 2 +- lib/core/logger.py | 1 - lib/parsers/parser.py | 3 +-- lib/processors/processor.py | 4 +--- lib/processors/syslog.py | 3 ++- lib/tasks/email.py | 2 +- lib/tasks/task.py | 20 +++++++------------- lib/tasks/xmpp.py | 1 - 11 files changed, 28 insertions(+), 40 deletions(-) diff --git a/lib/config/hostgroups.py b/lib/config/hostgroups.py index f6f6989..33e2a3b 100644 --- a/lib/config/hostgroups.py +++ b/lib/config/hostgroups.py @@ -1,15 +1,16 @@ - class HostGroupException(Exception): def __init__(self, msg): self.msg = msg def __str__(self): return repr(self.msg) - + + class HostGroupMissingArgumentException(HostGroupException): def __init__(self, missingArgument, hostgroupName): super(HostGroupMissingArgumentException, self).__init__("no " + missingArgument + " defined for Hostgroup " + hostgroupName) + class HostGroup: def __init__(self, name, **kwargs): self.name = name diff --git a/lib/config/parser.py b/lib/config/parser.py index 746358f..9c858ad 100644 --- a/lib/config/parser.py +++ b/lib/config/parser.py @@ -10,7 +10,7 @@ from members import Member from periods import CronPeriod, DatePeriod, IntervalPeriod from lib.services.service import Service -print id(Service) +#print id(Service) from lib.processors.processor import Processor from lib.parsers.parser import Parser from lib.tasks.task import Task @@ -20,14 +20,13 @@ MOD_PROCESSORS = "processors" MOD_PARSERS = "parsers" MOD_TASKS = "tasks" - - KEY_LAYOUTS = "layouts" KEY_HOSTGROUPS = "hostgroups" KEY_MEMBERS = "members" KEY_PERIODS = "periods" KEY_CORE = "core" + class ConfigurationException(Exception): def __init__(self, msg, log): log.e(msg) @@ -42,15 +41,14 @@ class ConfigParser: """ initializes a new ConfigParser Object - params: - log: pre configured logger Object to post messages while parsing" + :param log: pre configured logger Object to post messages while parsing" """ self.log = log self.hostgroups = {} self.members = {} self.periods = {} self.layouts = {} - self._loadedMods={MOD_SERVICES: {}, MOD_PROCESSORS: {}, MOD_TASKS: {}, MOD_PARSERS: {}} + self._loadedMods = {MOD_SERVICES: {}, MOD_PROCESSORS: {}, MOD_TASKS: {}, MOD_PARSERS: {}} def _create_new_config_dict(self): return {"members": {}, "periods": {}, "hostgroups": {}, "layouts": {}, "core": {}} @@ -64,14 +62,13 @@ class ConfigParser: """ reads the config File and returns a dictionary, while lowering the first keys - params: - configFilename: the path under which the configuration file should be found + :param configFilename: the path under which the configuration file should be found """ if not isfile(configFilename): msg = "config file not found at " + str(configFilename) raise ConfigurationException(msg, self.log) - self.configfilename = configFilename + self.configFilename = configFilename with open(configFilename) as cfgFile: config = cfgFile.read() @@ -102,6 +99,7 @@ class ConfigParser: def _load_module(self, clazz, modPart): """ imports and caches a module. + :param clazz: the filename of the module (i.e email, ping...) :param modPart: the folder of the module. (i.e services, parsers...) :return: the imported/cached module, or throws an error if it couldn't find it @@ -121,6 +119,7 @@ class ConfigParser: """ 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 @@ -166,6 +165,7 @@ class ConfigParser: def replace_pointer(self, objectList, replObjectList, id_list_func, id_get_func): """ replaces objects from the config by ids. + :param objectList: the list of objects to be iterated on :param replObjectList: the list of objects to replace :param id_list_func: function taking one argument as object and should return a list of config ids to replace @@ -205,15 +205,14 @@ class FullConfigParser(ConfigParser): def parse_config(self, configFilename): """ parses the json configuration and returns a list of layouts, - which contains all nessesary information of the config file. + which contains all necessary information of the config file. parses the full config Parsing will be done in 3 steps: 1. get raw Config Objects by just passing the values defined inside the config 2. replace references by objects, import services, tasks, parsers and processors 3. do sanity checks - params: - configFilename: indicates which configuration file to parse + :param configFilename: the configuration file to parse """ self.jsonDict = self._read_json_config(configFilename) @@ -230,7 +229,6 @@ class FullConfigParser(ConfigParser): creator = parsePeriodList periods = self._create_raw_Object(self.jsonDict[KEY_PERIODS], "Period", creator) - #2. import and replace items_func = lambda hostgroup: hostgroup.get_services() class_check = lambda service: isinstance(service, Service) @@ -244,7 +242,6 @@ class FullConfigParser(ConfigParser): for hg in hostgroups: services.extend(hg.get_services()) - items_func = lambda service: service.get_parser() class_check = lambda parser: isinstance(parser, Parser) self.replace_with_import(services, MOD_PARSERS, items_func, class_check) @@ -258,7 +255,6 @@ class FullConfigParser(ConfigParser): id_get_func = lambda member: member.id self.replace_pointer(hostgroups, members, id_list_func, id_get_func) - id_list_func = lambda service: service.get_periods() id_get_func = lambda period: period.get_name() self.replace_pointer(services, periods, id_list_func, id_get_func) diff --git a/lib/core/command.py b/lib/core/command.py index 3bd0d88..a9b8f62 100644 --- a/lib/core/command.py +++ b/lib/core/command.py @@ -3,6 +3,7 @@ from subprocess import Popen from subprocess import CalledProcessError from datetime import datetime as dt + class Command: def __init__(self, command, log): self.command = command diff --git a/lib/core/linspector_daemon.py b/lib/core/linspector_daemon.py index 52a7c32..b55ab19 100644 --- a/lib/core/linspector_daemon.py +++ b/lib/core/linspector_daemon.py @@ -13,4 +13,4 @@ class LinspectorDaemon(Daemon): #logger.writeLogToFile(_logfile, str(err)) print "failed" sys.exit(1) - time.sleep(1) + time.sleep(1) \ No newline at end of file diff --git a/lib/core/logger.py b/lib/core/logger.py index 8b5e398..9acc559 100644 --- a/lib/core/logger.py +++ b/lib/core/logger.py @@ -17,7 +17,6 @@ class Logger(): :param logfile: the file where to log. Logs are rotated by default. :param logfileLevel: the LoggingLevel for the file Logger. (DEBUG default) """ - logfile = path.expanduser(logfile) if not path.exists(path.dirname(logfile)): os.makedirs(path.dirname(logfile)) diff --git a/lib/parsers/parser.py b/lib/parsers/parser.py index 335b596..6906df0 100644 --- a/lib/parsers/parser.py +++ b/lib/parsers/parser.py @@ -10,5 +10,4 @@ class Parser: pass def generate_parse_result(self, result): - pass - + pass \ No newline at end of file diff --git a/lib/processors/processor.py b/lib/processors/processor.py index 988f696..c45b363 100644 --- a/lib/processors/processor.py +++ b/lib/processors/processor.py @@ -1,7 +1,5 @@ """ -Created on Jun 16, 2013 - -@author: rafael +The processor class for postprocessing polled data. """ diff --git a/lib/processors/syslog.py b/lib/processors/syslog.py index e2d0371..c75e158 100644 --- a/lib/processors/syslog.py +++ b/lib/processors/syslog.py @@ -9,5 +9,6 @@ class Syslog(Processor): def __init__(self): pass + def create(kwargs): - return Syslog(**kwargs) + return Syslog(**kwargs) \ No newline at end of file diff --git a/lib/tasks/email.py b/lib/tasks/email.py index 01db30c..fa7ebbf 100644 --- a/lib/tasks/email.py +++ b/lib/tasks/email.py @@ -2,7 +2,7 @@ The email task. """ -from lib.tasks.task import Task +from task import Task class EmailTask(Task): diff --git a/lib/tasks/task.py b/lib/tasks/task.py index 12d2269..a81597e 100644 --- a/lib/tasks/task.py +++ b/lib/tasks/task.py @@ -1,7 +1,5 @@ """ -Created on Jun 15, 2013 - -@author: Rafael Timmerberg +The task class. """ @@ -16,8 +14,7 @@ class Task: Be aware! this method can only get called once! - params: - taskType: the type of this task + :param taskType: the type of this task """ if hasattr(self, "_taskType"): raise Exception("taskType is only allowed to set once!") @@ -25,7 +22,7 @@ class Task: def get_task_type(self): """ - returns the type set by set_type_task + :return: the type set by set_type_task """ return self._taskType @@ -36,8 +33,7 @@ class Task: default does nothing - params: - msg: the msg for this task + :param msg: the msg for this task """ pass @@ -47,12 +43,10 @@ class Task: It determines if it has an appropriate type by comparing taskType with get_task_type(). Calls execute_task() if the type matches - params: - taskType: the type of the fail which is compared with get_task_type() - msg: the error message + :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 + :return: True if execute_task() is called succesfully, else False """ if self.get_task_type() == taskType: self.execute_task(msg) diff --git a/lib/tasks/xmpp.py b/lib/tasks/xmpp.py index b5cf146..ee407e4 100644 --- a/lib/tasks/xmpp.py +++ b/lib/tasks/xmpp.py @@ -18,6 +18,5 @@ class XmppTask(Task): pass - def create(taskDict): return XmppTask(**taskDict) \ No newline at end of file