
    Mh                        d 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dl
m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 G d dee          Z G d dee          Z G d dee          ZdS )zA workspace management CLI    )annotationsN)Path)Any)
JupyterApp)BoolUnicode   )__version__)	LabConfig)WorkspacesManagerdefaultc                       e Zd ZdZeZdZ ed ddiidfd ddiidf          Z e	d	dd
          Z
 e	d	dd          Zd fdZddZ xZS )WorkspaceListAppzAn app to list workspaces.a  
    Print all the workspaces available

    If '--json' flag is passed in, a single 'json' object is printed.
    If '--jsonlines' flag is passed in, 'json' object of each workspace separated by a new line is printed.
    If nothing is passed in, workspace ids list is printed.
    	jsonlinesTz+Produce machine-readable JSON Lines output.jsonz,Produce machine-readable JSON object output.)r   r   FzIf True, the output will be a newline-delimited JSON (see https://jsonlines.org/) of objects, one per JupyterLab workspace, each with the details of the relevant workspace)confighelpzUIf True, each line of output will be a JSON object with the details of the workspace.argsr   kwargsreturnNonec                l     t                      j        |i | t          | j                  | _        dS zInitialize the app.Nsuper
initializer   workspaces_dirmanagerselfr   r   	__class__s      `/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyterlab_server/workspaces_app.pyr   zWorkspaceListApp.initialize@   5    D+F+++()<==    c                *   | j                                         }| j        r(|D ]#}t          t	          j        |                     $dS | j        r#t          t	          j        |                     dS |D ]}t          |d         d                    dS )Start the app.metadataidN)r   list_workspacesr   printr   dumps)r    
workspaces	workspaces      r"   startzWorkspaceListApp.startE   s    \1133
> 	3' - -	dj++,,,,- -Y 	3$*Z(()))))' 3 3	i
+D122223 3r$   r   r   r   r   r   r   r   r   )__name__
__module____qualname____doc__r
   versiondescriptiondictflagsr   r   r   r   r.   __classcell__r!   s   @r"   r   r      s        $$GK D+t!45:

  &$0;
	 	 	E \	  I 4(	  D> > > > > >

3 
3 
3 
3 
3 
3 
3 
3r$   r   c                  4     e Zd ZdZeZdZd
 fdZdd	Z xZ	S )WorkspaceExportAppzA workspace export app.a  
    Export a JupyterLab workspace

    If no arguments are passed in, this command will export the default
        workspace.
    If a workspace name is passed in, this command will export that workspace.
    If no workspace is found, this command will export an empty workspace.
    r   r   r   r   r   c                l     t                      j        |i | t          | j                  | _        dS r   r   r   s      r"   r   zWorkspaceExportApp.initialize_   r#   r$   c                   t          | j                  dk    r)t          j        d           |                     d           | j        st
          n| j        d         }	 | j                            |          }t          t          j
        |                     dS # t          $ rY | j                            t          j
        t          t                      t          |                                         Y dS w xY w)r&   r	   z6Too many arguments were provided for workspace export.r   )r(   )datar'   N)len
extra_argswarningswarnexitDEFAULT_WORKSPACEr   loadr*   r   r+   	Exceptionlogerrorr7   )r    rawr-   s      r"   r.   zWorkspaceExportApp.startd   s    t!##MRSSSIIaLLL'+NDOA<N	Q))#..I$*Y''((((( 	Q 	Q 	QHNN4:d&N&N&NOOPPPPPP	Qs   ;B AC>=C>r/   r0   )
r1   r2   r3   r4   r
   r5   r6   r   r.   r9   r:   s   @r"   r<   r<   R   sk        !!GK> > > > > >
Q Q Q Q Q Q Q Qr$   r<   c                  j     e Zd ZdZeZdZ edddd          ZddiZ	d fdZ
ddZddZddZ xZS )WorkspaceImportAppzA workspace import app.z
    Import a JupyterLab workspace

    This command will import a workspace from a JSON file. The format of the
        file must be the same as what the export functionality emits.
    NTz
        Workspace name. If given, the workspace ID in the imported
        file will be replaced with a new ID pointing to this
        workspace name.
        )r   
allow_noner   namez!WorkspaceImportApp.workspace_namer   r   r   r   r   c                l     t                      j        |i | t          | j                  | _        dS r   r   r   s      r"   r   zWorkspaceImportApp.initialize   r#   r$   c                   t          | j                  dk    r/| j                            d           |                     d           |                                 5 }	 |                     |          }nM# t          $ r@}| j                            d|j        |           |                     d           Y d}~nd}~ww xY wddd           n# 1 swxY w Y   	 | j	        
                    |d         d         t          j        |                    }nG# t          $ r:}| j                            d|           |                     d           Y d}~nd}~ww xY w| j                            d|           dS )	r&   r	   z.One argument is required for workspace import.z%s is not a valid workspace:
%sNr'   r(   z#Workspace could not be exported:
%szSaved workspace: %s)r@   rA   rH   inforD   _smart_open	_validaterG   rN   r   saver   r+   )r    fidr-   eworkspace_paths        r"   r.   zWorkspaceImportApp.start   s   t1$$HMMJKKKIIaLLL 	3 NN3//		   @#(ANNN		!	 	 	 	 	 	 	 	 	 	 	 	 	 	 		!\..y/DT/JDJW`LaLabbNN 	 	 	HMM@!DDDIIaLLLLLLLL	 	+^<<<<<sT   CA43C4
B>>6B94C9B>>CCC9D 
E0EEc                6   | j         d         }|dk    rt          j        S t          |                                          }|                                s0| j                            d|           |                     d           |	                    d          S )Nr   -z%s does not exist.r	   zutf-8)encoding)
rA   sysstdinr   resolveexistsrH   rQ   rD   open)r    	file_name	file_paths      r"   rR   zWorkspaceImportApp._smart_open   s    OA&	9OO++--	!! 	HMM.	:::IIaLLL~~w~///r$   r?   c                    t          j        |          }d|vrd}t          |          | j        | j        rd| j        i|d<   nd|d         vrd}t          |          |S )Nr?   zThe `data` field is missing.r(   r'   z(The `id` field is missing in `metadata`.)r   rF   rG   workspace_name)r    r?   r-   msgs       r"   rS   zWorkspaceImportApp._validate   sz    IdOO	""0CC..  *t/B*%)4+>$?Ij!!:...<CC.. r$   r/   r0   )r   r   )r?   r   r   r   )r1   r2   r3   r4   r
   r5   r6   r   rc   aliasesr   r.   rR   rS   r9   r:   s   @r"   rL   rL   r   s        !!GK W		 	 	N :;G> > > > > >
= = = =*0 0 0 0       r$   rL   )r4   
__future__r   r   r[   rB   pathlibr   typingr   jupyter_core.applicationr   	traitletsr   r   _versionr
   r   r   workspaces_handlerr   rE   r   r<   rL    r$   r"   <module>rn      sh   !   " " " " " "  



              / / / / / / # # # # # # # # ! ! ! ! ! !       1 1 1 1 1 1  63 63 63 63 63z9 63 63 63rQ Q Q Q QY Q Q Q@N N N N NY N N N N Nr$   