From 4d7ded5e51302c3f41200733309c3a83e769306d Mon Sep 17 00:00:00 2001 From: RafTim Date: Sun, 20 Oct 2013 01:20:27 +0200 Subject: [PATCH] abstracted lish job printing --- linspector/config/parser.py | 2 ++ linspector/core/interface.py | 16 ++++++++++++++++ linspector/frontends/lish.py | 23 +++++++++++++---------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/linspector/config/parser.py b/linspector/config/parser.py index a44a10a..c69193a 100644 --- a/linspector/config/parser.py +++ b/linspector/config/parser.py @@ -240,6 +240,8 @@ class FullConfigParser(ConfigParser): creator = lambda name, values: HostGroup(name, **values) self.hostgroups = self._create_raw_Object(self.dict[KEY_HOSTGROUPS], "Hostgroup", creator) + + creator = parsePeriodList periods = self._create_raw_Object(self.dict[KEY_PERIODS], "Period", creator) diff --git a/linspector/core/interface.py b/linspector/core/interface.py index 12c25e6..9fc9d93 100644 --- a/linspector/core/interface.py +++ b/linspector/core/interface.py @@ -19,6 +19,7 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . """ +from collections import OrderedDict class LinspectorInterface(object): @@ -37,10 +38,25 @@ class LinspectorInterface(object): return self.jobHex def find_job_by_hex_string(self, hexString): + if hexString is None: + return None for job in self.jobs: if job.hex_string() == hexString: return job + def get_job_info_dict(self, job): + d = OrderedDict() + d["Job"] = job.hex_string() + d["Hostgroup"] = job.hostgroup.get_name() + d["Host"] = job.host + d["Service"] = str(job.service) + d["Members"] = str([member.name for member in job.members]) + d["Interval"] = str(job.job.trigger) + d["Next run"] = str(job.job.next_run_time) + d["Enabled"] = str(job._enabled) + d["Fails"] = str(job.jobThreshold) + return d + def get_enabled_layouts(self): self._config.get_enabled_layouts() diff --git a/linspector/frontends/lish.py b/linspector/frontends/lish.py index c2be84d..b6bf1ea 100644 --- a/linspector/frontends/lish.py +++ b/linspector/frontends/lish.py @@ -186,17 +186,19 @@ class LishCommander(Exit, ShellCommander, LogCommander): def help_python(self): print "executes python using 'exec'." + def print_color(self, color, text): + print color + str(text) + END + + def print_dict(self, dict): + for key, val in dict.items(): + tab = ":\t" + if len(str(key)) < 7: + tab += "\t" + + print str(key) + tab + str(val) + def print_jobs_infos(self, job): - #TODO: fix the output for "interval" and "next run" - print "Job:\t\t" + job.hex_string() + "\n" + \ - "Hostgroup:\t" + job.hostgroup.get_name() + "\n" + \ - "Host:\t\t" + job.host + "\n" + \ - "Service:\t" + str(job.service) + "\n" + \ - "Members:\t" + str([member.name for member in job.members]) + "\n" + \ - "Interval:\t" + str(job.job.trigger) + "\n" + \ - "Next run:\t" + str(job.job.next_run_time) + "\n" + \ - "Enabled:\t" + str(job._enabled) + "\n" + \ - "Fails:\t\t" + str(job.jobThreshold) + self.print_dict(self.interface.get_job_info_dict(job)) def do_job(self, text): text = shsplit(text) @@ -206,6 +208,7 @@ class LishCommander(Exit, ShellCommander, LogCommander): if job is None: print RED + "first parameter must be a job hex id! get a List of all ids by typing 'jobs list'\n" + END self.help_job() + return if len(text) == 1: self.print_jobs_infos(job)