3
dp                 @   s  d dl Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZ ddlmZ e jeddd	 Zejede jd
eede jdde	 edddd Zejede jdeede jdddddde jdddddde jdddddde jddedd d!d" Zejede jd#eedd$d% Zejede jd&e
 d'ed(e jd)ed'd*e jd+ddd,de jd-d.ddd/de jd0d1 Zejedd2d3 Zej d4d5 Zejede jdd6edd7d8e jd9d:e
 ded;d<e jd=d>eded?d<e jd@dAdedBdCe jdDdEdedFdCe jdGdHedId e jdJdKeddLdMe jdNdOdddPde jdQdRedSd e jdTdUedVd dWdX ZdS )Y    N   )list_interfaces)CONTEXT_SETTINGSUNKNOWN_OPTIONSExistingDirPathExistingFilePathUnexistingFilePathRegularExpressionPythonModulecheck_not_none   )__version__)Zcontext_settingsc               C   s   d S )N r   r   r   4/tmp/pip-build-7vycvbft/nipype/nipype/scripts/cli.pycli   s    r   logdir)typecallbackz-rz--regexz4Regular expression to be searched in each traceback.)r   r   helpc             C   sh   ddl m} xV|| D ]J\}}|j|rtjdt|  tj| tjdt|  tj| qW dS )zSearch for tracebacks content.

    Search for traceback inside a folder of nipype crash log files that match
    a given regular expression.

    Examples:

    nipypecli search nipype/wd/log -r '.*subject123.*'
    r   )iter_tracebacks-N)crash_filesr   searchclickecholen)r   regexr   filetracer   r   r   r      s    

r   	crashfilez--rerunTzRerun crashed node.)Zis_flag
flag_valuer   z-dz--debugz)Enable Python debugger when re-executing.z-iz
--ipydebugz*Enable IPython debugger when re-executing.z-wz--dirz#Directory where to run the node in.)r   r   c             C   sX   ddl m} |rdn|}|dkrFddl}ddlm} |jdddd	|_|| ||| dS )
zDisplay Nipype crash files.

    For certain crash files, one can rerun a failed node in a temp directory.

    Examples:

    nipypecli crash crashfile.pklz

    nipypecli crash crashfile.pklz -r -i

    r   )display_crash_fileZipythonr   N)ultratbVerboseLinux)modeZcolor_schemeZcall_pdb)r   r!   sysZIPython.corer"   ZFormattedTB
excepthook)r   ZrerundebugZipydebugdirr!   r&   r"   r   r   r   crash7   s    r*   	pklz_filec             C   s,   ddl m } ddlm} || }|| dS )z^Print the content of Nipype node .pklz file.

    Examples:

    nipypecli show node.pklz
    r   )pprintr   )loadpklN)r,   Zutils.filemanipr-   )r+   r,   r-   Zpkl_datar   r   r   showc   s    r.   moduleF)r   requiredr   	interface)r   r0   z--listz6List the available Interfaces inside the given module.z-hz--helpzShow help message and exit.c             C   s.  ddl }ddlm} ddlm} t|}|s@tj| jj	|  n|rH|sR|r| rt
|}	tjd x|	D ]}
tjdj|
 qjW n|o|r*d	j|}d
j| j|j|g| j }|j||d}t|| }|||}| jsz&y|j  W n   td Y nX W d|j  X n|j| jd}||| dS )zRun a Nipype Interface.

    Examples:

    nipypecli run nipype.interfaces.nipy --list

    nipypecli run nipype.interfaces.nipy ComputeMask --help
    r   Nr   )add_args_optionsr   )run_instancezAvailable Interfaces:z    {}zRun {} )descriptionprogzKAn error ocurred when trying to print the fullcommand help, printing usage.)args)argparseutilsr2   Zutils.nipype_cmdr3   boolr   r   commandZget_helpr   formatjoinZcommand_path__name__r7   ArgumentParsergetattr
print_helpprintprint_usage
parse_args)ctxr/   r1   listr   r8   r2   r3   Zmodule_givenZiface_namesZif_namer5   r6   Ziface_parsernoder7   r   r   r   runr   s4    




rH   c               C   s   t jt dS )z Print current version of Nipype.N)r   r   r   r   r   r   r   version   s    rI   c               C   s   dS )z*Export nipype interfaces to other formats.Nr   r   r   r   r   convert   s    rJ   z--interfacez'Name of the Nipype interface to export.)r   r0   r   z-mz--modulez&Module where the interface is defined.)r   r0   r   r   z-oz--outputz>JSON file name where the Boutiques descriptor will be written.z-cz--container-imagez8Name of the container image where the tool is installed.)r0   r   r   z-pz--container-typez0Type of container image (Docker or Singularity).z-xz--container-indexzJOptional index where the image is available (e.g. http://index.docker.io).z-gz--ignore-inputsz:List of interface inputs to not include in the descriptor.)r   multipler   z-vz	--verbosezPrint information messages.z-az--authorz-Author of the tool (required for publishing).z-tz--tagszRJSON string containing tags to include in the descriptor,e.g. "{"key1": "value1"}"c
             C   s,   ddl m}
 |
| |||||d||||	 dS )zkNipype to Boutiques exporter.

    See Boutiques specification at https://github.com/boutiques/schema.
    r   )generate_boutiques_descriptorTN)Znipype.utils.nipype2boutiquesrL   )r/   r1   Zcontainer_imageZcontainer_typeoutputZcontainer_indexverboseauthorZignore_inputstagsrL   r   r   r   	boutiques   s    QrQ   )r   instancer   r9   r   r   r   r   r   r	   r
   r    r   groupr   r;   Zargumentoptionr   r*   r.   strZpass_contextrH   rI   rJ   rQ   r   r   r   r   <module>   s   (

 

4
