#!/usr/bin/env python

import kimps, drmaa

 

def argsOption():

    usage = "usage: %prog -o ./cluster_out/ ./input_dir/"

    parser = kimps.OptionParser( usage=usage )

    parser.add_option( "-o", "--cluster_out",dest="cluster_out",help="out stream of sge")

    (options, args) = parser.parse_args()

    if len(args) != 1:

        parser.error("incorrect number of arguments")

    return options, args

 

# main

options,args = argsOption()

input_dir = args[0]

 

inpath = input_dir

outpath = options.cluster_out

if not(outpath): outpath = inpath

 

s = drmaa.Session()

s.initialize()

jt = s.createJobTemplate()

joblist = []

#kimps_ctime.stime( kimps.sys._getframe().f_code.co_filename )

inlist = kimps.glob.glob( inpath + '*.sh' )

for onein in inlist:

    kimps.os.chmod( onein, 0766 )

    inname = onein.split('/')[-1]

    innametag = '.'.join(inname.split('.')[:-1])

 

    jt.remoteCommand = onein

    jt.nativeSpecification = " -V -S /bin/bash -j y -cwd -o "+outpath+innametag+".qout"

    jt.joinFiles = True

    joblist.append( s.runJob( jt ) )

 

s.synchronize( joblist, drmaa.Session.TIMEOUT_WAIT_FOREVER, False)

 

for curjob in joblist:

#   print "Collecting job "+curjob

    retval = s.wait( curjob, drmaa.Session.TIMEOUT_WAIT_FOREVER )

#   print 'Job: '+ str(retval.jobId ) + 'finished with status '+ str(retval.hasExited)

 

s.deleteJobTemplate( jt )

s.exit()

Posted by 옥탑방람보
,