Ë
    :vžj˜  ã                  óÐ   — 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y)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   Fz«If 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.c                óX   •— t        ‰| �  |i |¤Ž t        | j                  «      | _        y©zInitialize the app.N©ÚsuperÚ
initializer   Úworkspaces_dirÚmanager©ÚselfÚargsÚkwargsÚ	__class__s      €úq/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/jupyterlab_server/workspaces_app.pyr   zWorkspaceListApp.initialize@   ó'   ø€ ä‰Ñ˜DÐ+ FÒ+Ü(¨×)<Ñ)<Ó=ˆ�ó    c                ó"  — | j                   j                  «       }| j                  r&|D ]   }t        t	        j
                  |«      «       Œ" y| j                  rt        t	        j
                  |«      «       y|D ]  }t        |d   d   «       Œ y)úStart the app.ÚmetadataÚidN)r   Úlist_workspacesr   Úprintr   Údumps)r   Ú
workspacesÚ	workspaces      r    ÚstartzWorkspaceListApp.startE   sj   € à—\‘\×1Ñ1Ó3ˆ
Ø�>Š>Û'�	Ü”d—j‘j Ó+Õ,ñ (à�YŠYÜ”$—*‘*˜ZÓ(Õ)ã'�	Ü�i 
Ñ+¨DÑ1Õ2ñ (r"   ©r   r   r   r   ÚreturnÚNone©r.   r/   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚversionÚdescriptionÚdictÚflagsr   r   r   r   r,   Ú__classcell__©r   s   @r    r   r      s‚   ø„ Ù$à€Gð€Kñ à +¨tÐ!4Ð5Ø:ð
ð
   &¨$ Ð0Ø;ð
ô	€Eñ ØØð\ô	€Iñ ØØð(ô	€Dõ>÷

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.
    c                óX   •— t        ‰| �  |i |¤Ž t        | j                  «      | _        yr   r   r   s      €r    r   zWorkspaceExportApp.initialize_   r!   r"   c                óê  — t        | j                  «      dkD  r&t        j                  d«       | j	                  d«       | j                  st
        n| j                  d   }	 | j                  j                  |«      }t        t        j                  |«      «       y# t        $ rN | j                  j                  t        j                  t        t        «       t        |¬«      ¬«      «      «       Y y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‰MÐRÔSØ�I‰I�aŒLà'+§¢Õ¸D¿O¹OÈAÑ<Nˆð	QØŸ™×)Ñ)¨#Ó.ˆIÜ”$—*‘*˜YÓ'Õ(øÜò 	QØ�H‰H�N‰Nœ4Ÿ:™:¤d´³ÄÈÄÔ&NÓOÖPð	Qús   Á!9B ÂAC2Ã1C2r-   r0   )
r1   r2   r3   r4   r
   r5   r6   r   r,   r9   r:   s   @r    r<   r<   R   s   ø„ Ù!à€Gð€Kõ>÷
Qr"   r<   c                  ód   ‡ — 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_namec                óX   •— t        ‰| �  |i |¤Ž t        | j                  «      | _        yr   r   r   s      €r    r   zWorkspaceImportApp.initialize‰   r!   r"   c                óÀ  — t        | j                  «      dk7  r,| j                  j                  d«       | j	                  d«       | j                  «       5 }	 | j                  |«      }ddd«       	 | j                  j                  d   d   t        j                  |«      «      }| j                  j                  d«       y# t        $ rB}| j                  j                  d|j                  |«       | j	                  d«       Y d}~Œ¡d}~ww xY w# 1 sw Y   ŒªxY w# t        $ r7}| j                  j                  d|«       | j	                  d«       Y d}~Œ²d}~ww xY w)	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Ò$Ø�H‰H�M‰MÐJÔKØ�I‰I�aŒLà×ÑÔ 3ðØ ŸN™N¨3Ó/�	÷  ð	Ø!Ÿ\™\×.Ñ.¨y¸Ñ/DÀTÑ/JÌDÏJÉJÐW`ÓLaÓbˆNð
 	�‰�‰Ð+¨^Õ<øô ò Ø—‘—‘Ð@À#Ç(Á(ÈAÔNØ—	‘	˜!—‘ûðú÷  Ðûô ò 	Ø�H‰H�M‰MÐ@À!ÔDØ�I‰I�a�L‰Lûð	úsH   ÁDÁCÁ15D Ã	DÃ8D	ÄDÄ	DÄDÄDÄ	EÄ&-EÅEc                ó  — | j                   d   }|dk(  rt        j                  S t        |«      j	                  «       }|j                  «       s-| j                  j                  d|«       | j                  d«       |j                  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£   so   € Ø—O‘O AÑ&ˆ	à˜ÒÜ—9‘9Ðä˜“O×+Ñ+Ó-ˆ	à×ÑÔ!Ø�H‰H�M‰MÐ.°	Ô:Ø�I‰I�aŒLà�~‰~ wˆ~Ó/Ð/r"   c                óÐ   — t        j                  |«      }d|vrd}t        |«      ‚| j                  �| j                  rd| j                  i|d<   |S 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±   s}   € Ü—I‘I˜d“Oˆ	à˜Ñ"Ø0ˆCÜ˜C“.Ð ð ×ÑÐ*¨t×/BÒ/BØ%)¨4×+>Ñ+>Ð$?ˆI�jÑ!ð
 Ðð	 ˜ :Ñ.Ñ.Ø<ˆ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   sM   ø„ Ù!à€Gð€Kñ ØØØðô		€Nð Ð:Ð;€Gõ>ó
=ó*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      sc   ðñ !Ý "ã Û 
Û Ý Ý å /ß #å !Ý Ý 1ð Ð ô63�z 9ô 63ôrQ˜ Yô Qô@N˜ Yõ Nr"   