
    5i|                     Z    d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d Z	d Z
d Zd	dZy)
    )print_functionN)file_load_utils)err_exitc                    g }| D ]_  }i }|d   }|j                         |d<   |d   |d<   |d   }dt        j                  j                  |      z   |d<   |j	                  |       a d|i}t        d	       t        |       |S )
Nhandlerproj_idsrc_file_idfile_id	trg_fname/parentFileszFile mount manifest:)get_proj_idospathdirnameappendprint)to_mount
files_listfile_rec
file_entryfile_handler	file_namefiles_manifests          /home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/bindings/mount_all_inputs.py_build_mount_manifestr      s    J &
	* , 8 8 :
9 ( 7
9[)	"RWW__Y%??
8*%& z*N	
 !	.    c                     d }t         j                  d   j                  t         j                        D ].  }t         j                  j                  ||       } ||      s,|c S  y )Nc                     t         j                  j                  |       xr$ t        j                  | t         j                        S N)r   r   isfileaccessX_OK)fpaths    r   is_exez_which.<locals>.is_exe(   s)    ww~~e$B5"'')BBr   PATH)r   environsplitpathsepr   join)programr&   r   exe_files       r   _whichr.   '   sW    C 

6"((4 77<<g.(O r   c                     t        j                  t        j                         d      \  }}i }d }| D ]<  }||vr||   } ||dz   |d   |        ||dz   |d   |        ||dz   |d   |       > |S )	z~
    Create a dict of values for the mounted files. This is similar to the variables created
    when running a bash app.
    Nc                     | |vr||| <   y y r!    )keyvaluedict_s      r   add_if_no_collisionz-_gen_helper_dict.<locals>.add_if_no_collision<   s    eE#J r   _pathr   _namebasename_prefixprefix)r   analyze_bash_varsget_input_json_file)filtered_inputsfile_key_descs_ignoreflattened_dictr5   input_input_var_dicts          r   _gen_helper_dictrC   1   s     .??++-t5NG N " Z''/FW,nV.DnUFW,nZ.H.YFY.x0H.YZ r   c                    t        d       t        j                  d   }t        j                  j	                  |d      }t        j                  j	                  |d      }t        d      }|t        d       t        j                  d|g       	 t        j                         }t        j                  |      \  }}}	| rt        j                  ||       }g }|j                         D ]  }|j!                  |        t#        |      }t%        |d      5 }t'        j(                  ||       ddd       t        j                  |dg      }t        dt+        |      z          t+        t-        t        j                  ddg                  }t+        t-        t        j                  ddg                  }|d|d|||g}|rddg|dd t        t        j                  |             t        d       t        j.                  d|ddg       t1        |      }|S # t        $ r# d	j                        }
|
d
z  }
t        |
        w xY w# 1 sw Y   xY w)a  
    :param exclude: List of input variables that should not be mounted.
    :type exclude: Array of strings
    :returns: dict of lists of strings where each key is the input variable
                and each list element is the full path to the file that has
                been mounted.
    :param verbose: Start dxfuse with '-verbose 2' logging
    :type verbose: boolean


    This function mounts all files that were supplied as inputs to the app.
    By convention, if an input parameter "FOO" has value

        {"$dnanexus_link": "file-xxxx"}

    and filename INPUT.TXT, then the linked file will be mounted into the
    path:

        $HOME/in/FOO/INPUT.TXT

    If an input is an array of files, then all files will be placed into
    numbered subdirectories under a parent directory named for the
    input. For example, if the input key is FOO, and the inputs are {A, B,
    C}.vcf then, the directory structure will be:

        $HOME/in/FOO/0/A.vcf
                     1/B.vcf
                     2/C.vcf

    Zero padding is used to ensure argument order. For example, if there are
    12 input files {A, B, C, D, E, F, G, H, I, J, K, L}.txt, the directory
    structure will be:

        $HOME/in/FOO/00/A.vcf
                     ...
                     11/L.vcf

    This allows using shell globbing (FOO/*/*.vcf) to get all the files in the input
    order and prevents issues with files which have the same filename.zMounting inputs...HOMEinzmount-manifest.jsondxfuseNz&dxfuse is not installed on this systemmkdirz0Error: Could not find the input json file: {0}.
zE       This function should only be called from within a running job.wz-versionzUsing dxfuse version idz-uz-gz-uidz-gidz-verbose2   zDone mounting inputs.findz-name*)r   r   r(   r   r+   r.   r   
subprocesscheck_outputr   r<   get_job_input_filenamesIOErrorformatfilter_dictvaluesextendr   openjsondumpstrintcallrC   )excludeverbosehome_dir	mount_dirmount_manifest_file
dxfuse_cmdjob_input_filedirsinputsrestmsgr   	ival_listr   mfiledxfuse_versionuidgidcmdhelper_varss                       r   mount_all_inputsro   K   s   R 

zz&!HXt,I'',,x1FG!J9:Wi01(<<>,DD^Tfd  ,,VW= H]]_ #		"# +84N	!3	' )5		.%()  ,,j*-EFN	
!C$7
78
c*))4,78
9C
c*))4,78
9CvsFC<O
PC$Aa	*
!
!#
&'	
!"OOVY56"6*KE  AHHXVVc
	 ) )s   -H I,H?I)NF)
__future__r   rO   rX   r   
dxpy.utilsr   dxpy.exceptionsr   r   r.   rC   ro   r1   r   r   <module>rs      s.   " &   	 & $4Yr   