3
XdX                 @   sb   d Z ddlZddlZddlZddlmZ ejded dd Zd	d
 Z	G dd de
Zdd ZdS )a   The minc module provides classes for interfacing with the `MINC
<http://www.bic.mni.mcgill.ca/ServicesSoftware/MINC>`_ command line tools.
This module was written to work with MINC version 2.2.00.

Author: Carlo Hamalainen <carlo@carlo-hamalainen.net>
        http://carlo-hamalainen.net
    N   )CommandLinealways)categoryc               C   s   t j dk	S )z/Returns True if and only if MINC is installed.'N)Infoversion r   r   M/var/www/html/virt/lib/python3.6/site-packages/nipype/interfaces/minc/base.py
check_minc   s    r
   c               C   s   t   S )z4Returns True if and only if MINC is *not* installed.)r
   r   r   r   r	   no_minc   s    r   c               @   s   e Zd ZdZedd ZdS )r   z^Handle MINC version information.

    version refers to the version of MINC on the system
    c        
      C   s   yt ddddj } W n tk
r*   dS X | jj}dd }dd	 }d
d }dd }ddddd}xT|jdD ]F}x@d|fd|fd|fd|fgD ] \}}	|	|dk	r|	|||< qW qnW |S )zCheck for minc version on the system

        Parameters
        ----------
        None

        Returns
        -------
        version : dict
           Version number as dict or None if MINC not found

        Zmincinfoz-versionZ	allatonce)commandargsZterminal_outputNc             S   s   d| kr| j dd j S d S )Nprogram:   )splitstrip)sr   r   r	   read_program_version<   s    z*Info.version.<locals>.read_program_versionc             S   s   d| kr| j dd j S d S )Nlibmincr   r   )r   r   )r   r   r   r	   read_libminc_versionA   s    z*Info.version.<locals>.read_libminc_versionc             S   s(   d| kr$dj | jddd  j S d S )Nnetcdf r   r   )joinr   r   )r   r   r   r	   read_netcdf_versionF   s    z)Info.version.<locals>.read_netcdf_versionc             S   s   d| kr| j dd j S d S )NZHDF5r   r   )r   r   )r   r   r   r	   read_hdf5_versionK   s    z'Info.version.<locals>.read_hdf5_version)mincr   r   hdf5
r   r   r   r   )r   runIOErrorZruntimestdoutr   )
Zcloutoutr   r   r   r   versionslnamefr   r   r	   r   %   s(    zInfo.versionN)__name__
__module____qualname____doc__staticmethodr   r   r   r   r	   r      s   r   c             C   s   t jj| d d }dd | D }t jj|}t j }|dkrpt jjt jj|t jj| d d d | d S t jjt jj||d | d S dS )a  
    Try to work out a sensible name given a set of files that have
    been combined in some way (e.g. averaged). If we can't work out a
    sensible prefix, we use the first filename in the list.

    Examples
    --------

    >>> from nipype.interfaces.minc.base import aggregate_filename
    >>> f = aggregate_filename(['/tmp/foo1.mnc', '/tmp/foo2.mnc', '/tmp/foo3.mnc'], 'averaged')
    >>> os.path.split(f)[1] # This has a full path, so just check the filename.
    'foo_averaged.mnc'

    >>> f = aggregate_filename(['/tmp/foo1.mnc', '/tmp/blah1.mnc'], 'averaged')
    >>> os.path.split(f)[1] # This has a full path, so just check the filename.
    'foo1_averaged.mnc'

    r   c             S   s(   g | ] }t jjt jj|d  d qS )r   r   )ospathsplitextr   ).0xr   r   r	   
<listcomp>t   s    z&aggregate_filename.<locals>.<listcomp> _z.mncN)r,   r-   r   commonprefixgetcwdabspathr   r.   )filesZ
new_suffixr-   namescommon_prefixr   r   r	   aggregate_filename_   s    &r:   )r*   r,   os.pathwarningsbaser   filterwarningsUserWarningr
   r   objectr   r:   r   r   r   r	   <module>
   s   @