From 180b6ef99f9353b96a8ab07e9ad99dc323b99806 Mon Sep 17 00:00:00 2001
From: Wouter Peters <wouter.peters@wur.nl>
Date: Mon, 6 Sep 2010 12:08:02 +0000
Subject: [PATCH] baseclass to contain job control object class PlatForm

---
 da/baseclasses/jobcontrol.py | 95 ++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100755 da/baseclasses/jobcontrol.py

diff --git a/da/baseclasses/jobcontrol.py b/da/baseclasses/jobcontrol.py
new file mode 100755
index 00000000..723290e6
--- /dev/null
+++ b/da/baseclasses/jobcontrol.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+# jobcontrol.py
+
+"""
+Author : peters 
+
+Revision History:
+File created on 06 Sep 2010.
+
+"""
+
+import sys
+import os
+import logging
+import subprocess
+
+class PlatForm(object):
+    """ This specifies platform dependent options under generic object calls. A platform object is used to control and submit jobs"""
+
+    def __init__(self):
+        self.Identifier     = 'iPad'    # the identifier gives the plaform name
+        self.Version        = '1.0'     # the platform version used
+        print self
+
+    def __str__(self):
+
+        msg1  = '%s object initialized'%self.Identifier ; logging.debug(msg1)
+        msg2  = '%s version: %s'%(self.Identifier,self.Version) ; logging.debug(msg2)
+
+        return msg1+'\n'+msg2
+
+    def GetJobTemplate(self,joboptions={}):
+        """ Return the job template for a given computing system, and fill it with options from the dictionary provided as argument"""
+
+        template = """## \n"""+ \
+                   """## This is a set of dummy names, to be replaced by values from the dictionary \n"""+ \
+                   """## Please make your own platform specific template with your own keys and place it in a subfolder of the da package.\n """+ \
+                   """## \n"""+ \
+                   """ \n"""+ \
+                   """#$ jobname \n"""+ \
+                   """#$ jobaccount \n"""+ \
+                   """#$ jobnodes \n"""+ \
+                   """#$ jobtime \n"""+ \
+                   """#$ jobshell \n """+ \
+                   """\n """
+
+        for k,v in joboptions.iteritems():
+            while k in template:
+                template = template.replace(k,v)
+
+        return template
+
+    def WriteJob(self,DaCycle,template, jobid):                   
+        """ This method writes a jobfile to the exec dir"""
+        #
+        # Done, write jobfile
+        # 
+        targetdir               = os.path.join(DaCycle.da_settings['dir.exec'])
+        jobfile                 = os.path.join(targetdir,'jb.%s.jb'%jobid)
+        f                       = open(jobfile,'w')
+        dummy                   = f.write(template)
+        dummy                   = f.close()
+        dummy                   = os.chmod(jobfile,477)                  
+
+        msg = "A job file was created (%s)"%jobfile  ; logging.debug(msg)
+
+        return jobfile
+        
+
+    def SubmitJob(self,jobfile):                   
+        """ This method submits a jobfile to the queue, and returns the queue ID """
+        
+        cmd     = ['sh',jobfile]
+        jobid   = subprocess.call(cmd)
+         
+        return jobid
+
+    def KillJob(self,jobid):                   
+        """ This method kills a running job """
+        
+        output = subprocess.Popen(['qdel',jobid], stdout=subprocess.PIPE).communicate()[0]  ; logging.info(output)
+
+        return output
+
+    def StatJob(self,jobid):                   
+        """ This method gets the status of a running job """
+        import subprocess
+        
+        output = subprocess.Popen(['qstat',jobid], stdout=subprocess.PIPE).communicate()[0]  ; logging.info(output)
+
+        return output
+
+
+if __name__ == "__main__":
+    pass
-- 
GitLab