<s> import sys <EOL> import os <EOL> import subprocess <EOL> try : <EOL> import cPickle <EOL> except ImportError : <EOL> import pickle as cPickle <EOL> class MultiTarget : <EOL> def __init__ ( self , commands ) : <EOL> self . commands = commands <EOL> def execute ( self ) : <EOL> task_id = int ( os . environ [ '<STR_LIT>' ] ) <EOL> if task_id is None : <EOL> RuntimeError ( "<STR_LIT>" ) <EOL> if task_id < <NUM_LIT:1> or task_id > len ( self . commands ) : <EOL> RuntimeError ( "<STR_LIT>" , task_id , len ( self . commands ) ) <EOL> ( job , outfile ) = self . commands [ task_id - <NUM_LIT:1> ] <EOL> if outfile is None : <EOL> ret = subprocess . call ( job . split ( ) ) <EOL> else : <EOL> file = open ( outfile , "<STR_LIT:w>" ) <EOL> ret = subprocess . call ( job . split ( ) , stderr = file , stdout = file ) <EOL> file . close ( ) <EOL> sys . exit ( ret ) <EOL> def makeRunnable ( self , tempDir ) : <EOL> from sonLib . bioio import getTempFile <EOL> from jobTree . src . bioio import workflowRootPath <EOL> pickleFile = tempDir . getTempFile ( "<STR_LIT>" ) <EOL> fileHandle = open ( pickleFile , '<STR_LIT:w>' ) <EOL> cPickle . dump ( self , fileHandle , cPickle . HIGHEST_PROTOCOL ) <EOL> fileHandle . close ( ) <EOL> multijobexec = os . path . join ( workflowRootPath ( ) , "<STR_LIT>" , "<STR_LIT>" ) <EOL> jtPath = os . path . split ( workflowRootPath ( ) ) [ <NUM_LIT:0> ] <EOL> return "<STR_LIT>" % ( multijobexec , pickleFile , jtPath ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> fileHandle = open ( sys . argv [ <NUM_LIT:1> ] , '<STR_LIT:r>' ) <EOL> sys . path += [ sys . argv [ <NUM_LIT:2> ] ] <EOL> multitarget = cPickle . load ( fileHandle ) <EOL> fileHandle . close ( ) <EOL> multitarget . execute ( ) </s>
