3
d                 @   sL   d Z ddlZddlZddlmZ ddlmZ ddlmZ G dd	 d	eZ	dS )
z+Parallel workflow execution via PBS/Torque
    N   )CommandLine   )SGEGraphPlugin)loggerc               @   s   e Zd ZdZdZdd ZdS )PBSGraphPlugina5  Execute using PBS/Torque

    The plugin_args input to run can be used to control the SGE execution.
    Currently supported options are:

    - template : template to use for batch job submission
    - qsub_args : arguments to be prepended to the job execution script in the
                  qsub call

    z	
#PBS -V
c             C   sv  t jj|d \}}t jj|d}t|d
}|jd xt|D ]\}}	|| }
| j|
ddg\}}t jj|	\}}dj|jdd d }d	j|d
tj	|	f f}t jj|d| }t|d}|j| |j
  W d Q R X d}||krdd || D }t|rddj| }|jd||||f  qDW W d Q R X tdtt jddd}d| |j_|j  tjd d S )Nr   zsubmit_jobs.shwtz#!/usr/bin/env sh
template	qsub_args.r   
z%s %szbatchscript_%s.sh c             S   s   g | ]}d | qS )z$job%05d ).0Zjobidr   r   B/tmp/pip-build-7vycvbft/nipype/nipype/pipeline/plugins/pbsgraph.py
<listcomp>/   s    z0PBSGraphPlugin._submit_graph.<locals>.<listcomp>z-W depend=afterok:%s:zjob%05d=`qsub %s %s %s`
shFZ	allatonce)environZresource_monitorZterminal_outputz%szsubmitted all jobs to queue)ospathsplitjoinopen
writelines	enumerate	_get_argssys
executablecloselenr   dictr   inputsargsrunr   info)selfZpyfilesZdependenciesZnodesZ	batch_dir_ZsubmitjobsfilefpidxZpyscriptnoder	   r
   nameZbatchscriptZbatchscriptfileZbatchfpdepsvaluescmdr   r   r   _submit_graph   s>    



zPBSGraphPlugin._submit_graphN)__name__
__module____qualname____doc__	_templater0   r   r   r   r   r      s   
r   )
r4   r   r   Zinterfaces.baser   Zsgegraphr   baser   r   r   r   r   r   <module>   s   