Commit 180b6ef9 authored by Peters, Wouter's avatar Peters, Wouter
Browse files

baseclass to contain job control object class PlatForm

parent 2499ceb7
#!/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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment