From 807248a38d19a98e5d5247018c6a51f541dadd6b Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Tue, 19 Jan 2016 08:58:12 +0100 Subject: [PATCH 1/5] added .idea to gitignore, which contains PyCharm settings for the project. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 89a63b8..a14df7b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ dist/* *~ .i3pystatus-* ci-build +.idea/ From 6925770e4f0b8bf2f7376287b6c7231c89998db6 Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Tue, 19 Jan 2016 09:38:47 +0100 Subject: [PATCH 2/5] Added module for tracking the status of Batch computing jobs on a cluster running the Sun Grid Engine (SGE) --- i3pystatus/sge.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 i3pystatus/sge.py diff --git a/i3pystatus/sge.py b/i3pystatus/sge.py new file mode 100644 index 0000000..5bb35cf --- /dev/null +++ b/i3pystatus/sge.py @@ -0,0 +1,53 @@ +import subprocess + +from lxml import etree + +from i3pystatus import IntervalModule + + +class SGETracker(IntervalModule): + """ + Used to display status of Batch computing jobs on a cluster running Sun Grid Engine. + The data is collected via ssh, so a valid ssh address must be specified. + + Requires lxml. + """ + + interval = 60 + + settings = ( + ("ssh", "The SSH connection address. Can be user@host or user:password@host or user@host -p PORT etc."), + 'color', 'format' + ) + required = ("ssh",) + + format = "SGE qw: {queued} / r: {running} / Eqw: {error}" + on_leftclick = None + color = "#ffffff" + + def parse_qstat_xml(self): + xml = subprocess.check_output("ssh {0} \"qstat -f -xml\"".format(self.ssh), stderr=subprocess.STDOUT, + shell=True) + root = etree.fromstring(xml) + jobs = root.xpath('//job_info/job_info/job_list') + + job_dict = {'qw': 0, 'Eqw': 0, 'r': 0} + + for j in jobs: + job_dict[j.find("state").text] += 1 + + return job_dict + + def run(self): + jobs = self.parse_qstat_xml() + + fdict = { + "queued": jobs['qw'], + "error": jobs['Eqw'], + "running": jobs['r'] + } + + self.output = { + "full_text": self.format.format(**fdict).strip(), + "color": self.color + } From f32c8e06506727f1fe2182376949e9ba8d333ace Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Tue, 19 Jan 2016 10:17:50 +0100 Subject: [PATCH 3/5] reverted .gitignore and fixed indents of sge.py --- .gitignore | 1 - i3pystatus/sge.py | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a14df7b..89a63b8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ dist/* *~ .i3pystatus-* ci-build -.idea/ diff --git a/i3pystatus/sge.py b/i3pystatus/sge.py index 5bb35cf..578a6bd 100644 --- a/i3pystatus/sge.py +++ b/i3pystatus/sge.py @@ -26,8 +26,9 @@ class SGETracker(IntervalModule): color = "#ffffff" def parse_qstat_xml(self): - xml = subprocess.check_output("ssh {0} \"qstat -f -xml\"".format(self.ssh), stderr=subprocess.STDOUT, - shell=True) + xml = subprocess.check_output("ssh {0} \"qstat -f -xml\"".format(self.ssh), + stderr=subprocess.STDOUT, + shell=True) root = etree.fromstring(xml) jobs = root.xpath('//job_info/job_info/job_list') From 0fce823952b9f6e165346fd35942b33f38abbea1 Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Wed, 20 Jan 2016 09:09:32 +0100 Subject: [PATCH 4/5] fixed a bug of running jobs not being displayed. --- i3pystatus/sge.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/i3pystatus/sge.py b/i3pystatus/sge.py index 578a6bd..989558f 100644 --- a/i3pystatus/sge.py +++ b/i3pystatus/sge.py @@ -26,15 +26,16 @@ class SGETracker(IntervalModule): color = "#ffffff" def parse_qstat_xml(self): - xml = subprocess.check_output("ssh {0} \"qstat -f -xml\"".format(self.ssh), + xml = subprocess.check_output("ssh {0} \"qstat -xml\"".format(self.ssh), stderr=subprocess.STDOUT, shell=True) root = etree.fromstring(xml) - jobs = root.xpath('//job_info/job_info/job_list') - job_dict = {'qw': 0, 'Eqw': 0, 'r': 0} + + for j in root.xpath('//job_info/job_info/job_list'): + job_dict[j.find("state").text] += 1 - for j in jobs: + for j in root.xpath('//job_info/queue_info/job_list'): job_dict[j.find("state").text] += 1 return job_dict From 691453950ba0322c86da3e218328b19ab3a050f5 Mon Sep 17 00:00:00 2001 From: Jan Oliver Oelerich Date: Wed, 20 Jan 2016 09:11:30 +0100 Subject: [PATCH 5/5] fixed indentation --- i3pystatus/sge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i3pystatus/sge.py b/i3pystatus/sge.py index 989558f..5ffa3c4 100644 --- a/i3pystatus/sge.py +++ b/i3pystatus/sge.py @@ -31,7 +31,7 @@ class SGETracker(IntervalModule): shell=True) root = etree.fromstring(xml) job_dict = {'qw': 0, 'Eqw': 0, 'r': 0} - + for j in root.xpath('//job_info/job_info/job_list'): job_dict[j.find("state").text] += 1