
    5i:                         d dl Z d dlZd dlZd dlZddlmZmZ ddlmZ ddl	m
Z
 d dl mZ dZdZd	Zd
Zd Zd Zd Zd Zd Zd Zy)    N   )REDBOLD)err_exit)get_app_from_path)platform_notebook_server_10x_loupe_serverserver_running   c                 p    ddd| ddg}|dddj                  ||      d	gz  }t        j                  |       y
)z
    Setup an ssh tunnel to the given job-id.  This will establish
    the port over the given local_port to the given remote_port
    and then exit, keeping the tunnel in place until the job is
    terminated.
    dxsshz--suppress-running-checkz-ozStrictHostKeyChecking noz-fz-Lz{0}:localhost:{1}z-NN)format
subprocess
check_call)job_id
local_portremote_portcmds       }/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/ssh_tunnel_app_support.pysetup_ssh_tunnelr      sG     2FDB\
]CD$+22:{KTRRC#    c                 r   t         j                  j                  dj                  |              t         j                  j	                          t        j                  |       }t        |d   vr|d   dk7  rt        j                  t               t         j                  j                  d       t         j                  j	                          t        j                  |       }t        |d   vr	|d   dk7  r|d   dk(  r<t        d      dz   }|dz  }|t        d	j                  |             z  }t        |       y
y
)zJ
    Poll for the job to start running and post the SERVER_READY_TAG.
    z+Waiting for server in {0} to initialize ...tagsstatefailed.zError:z Server failed to run.
z.You may want to check the job logs by running:zdx watch {0}N)sysstdoutwriter   flushdxpydescribeSERVER_READY_TAGtimesleepSLEEP_PERIODr   r   r   )r   descmsgs      r   poll_for_server_runningr+   +   s     JJBII&QRJJ== D
$v,
.4=H3L

< 



}}V$	 $v,
.4=H3L G} (m88??tN))&122	 !r   c                     t         dk(  s	t         dk(  rd| g} nt         dk(  rd| g} nt         dk(  rd| g} t        j                  |        y)	z
    Take the given command and use the OS to automatically open the appropriate
    resource.  For instance, if a URL is provided, this will have the OS automatically
    open the URL in the default web browser.
    linuxlinux2zxdg-opendarwinopenwin32startN)r   r   r   )r   s    r   multi_platform_openr3   A   sM     7h(23	X	sm	W	n#r   c            	          t        j                  t        d      } | D cg c]&  }t        t        j                  |d         d         ( }}|S c c}w )z<
    Get the valid version numbers of the notebook app.
    T)nameall_versionsidversion)r#   	find_appsNOTEBOOK_APPstrr$   )notebook_appsappversionss      r   get_notebook_app_versionsr?   P   sI     NN4HMDQRSDMM#d),Y78RHRO Ss   +Ac           	      x    |        | j                   ry| j                  t        dj                  t        | j                              }|
d|v r|d   }nvt        d      dj                  | j                        z   }|t        dj                  t        t                                 z  }t        |       ndj                  t              }dd	|d
j                  | j                        g}|| j                  D cg c]  }dj                  |       c}z  }|dj                  | j                        dddd| j                  gz  }| j                  r|dgz  }| j                  r|dj                  | j                        gz  }t!        j"                  |      j%                         }t'        |       | j                  dv rd}t)        || j*                         | j,                  r/t/        dj                  | j*                               t1        d       t1        dj                  | j*                               yc c}w )z%
    Launch the notebook server.
    Nzapp-{0}/{1}r7   zWarning:z3 Invalid notebook version: {0}
Valid versions are: z{0}app-{0}r   runz-inotebook_type={0}z-iinput_files={0}-itimeout={0}-y--brief--allow-ssh--instance-typez-iinstall_spark=truez-isnapshot={0}>   jupyterjupyter_labjupyter_notebooki"  http://localhost:{0}AA web browser should have opened to connect you to your notebook.If no browser appears, or if you need to reopen a browser at any point, you should be able to point your browser to http://localhost:{0})only_check_configr8   r   r   r:   r   r   r;   r?   r   notebook_typenotebook_filestimeoutinstance_typesparksnapshotr   check_outputstripr+   r   portopen_serverr3   print)argsssh_config_check
executabler*   r   fr   r   s           r   run_notebookr^   Y   s   
  ||&}';';L$,,'WX
!dj&8#D)Jj/$Z$a$abfbnbn$ooC4S)B)D%EFGGCSM%%l3
 
$9$@$@ASAS$T
UC43F3FGa&&q)GGCO""4<<0$	=RceiewewxxCzz&''}} ''677$$S)//1FF#KKVTYY4299$))DEQR	  U  \  \  ]a  ]f  ]f  g  h% Hs   :H7c           	         dddj                  t              g}|| j                  D cg c]  }dj                  |       c}z  }|dj                  | j                  dddd	| j                        gz  }t        j                  |      j                         }t        |       d
}t        || j                  |       | j                  r/t        dj                  | j                               t        d       t        dj                  | j                               t        dj                  | j                               t        dj                  |             y c c}w )Nr   rB   rA   z-iloupe_files={0}rC   rD   rE   rF   rG   i  rK   rL   rM   zgYour Loupe session is scheduled to terminate in {0}.  If you wish to terminate before this, please run:zdx terminate {0})r   	LOUPE_APPloupe_filesrQ   rR   r   rU   rV   r+   r   rW   rX   r3   rY   )rZ   r   r]   r   r   s        r   	run_louperb      sG   	((3
4C43C3CDa&&q)DDCO""4<<y-QbdhdvdvwxxC$$S)//1FF#KVTYY4299$))DEQR	  U  \  \  ]a  ]f  ]f  g  h	
s
z
z{  |H  |H  I  J	

#
#F
+, Es   E)r   r   r&   r#   utils.printingr   r   
exceptionsr   utils.resolverr   r   r:   r`   r%   r(   r   r+   r3   r?   r^   rb    r   r   <module>rg      sT   "     '   - !	# 	,*hZ-r   