%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/duplicity/backends/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/duplicity/backends/__pycache__/megav3backend.cpython-312.pyc

�

�2e�&����ddlZddlZddlZddlZddlmZGd�dejj�Z	ejjde	�ejjjdg�y)�N)�BackendExceptionc�f�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dd�Zd
�Zd�Zd�Zy)�
Megav3BackendaxBackend for MEGA.nz cloud storage, only one that works for accounts created since Nov. 2018
    See https://github.com/megous/megatools/issues/411 for more details

    This MEGA backend resorts to official tools (MEGAcmd) as available at https://mega.nz/cmd
    MEGAcmd works through a single binary called "mega-cmd", which keeps state (for example,
    persisting a session). Multiple "mega-*" shell wrappers (ie. "mega-ls") exist as the user
    interface to "mega-cmd" and MEGA API
    The full MEGAcmd User Guide can be found in the software's GitHub page below :
    https://github.com/meganz/MEGAcmd/blob/master/UserGuide.mdc��tjjj||�|j	d�|j	d�|j	d�|j	d�|j	d�|j	d�|j	d�|j	d�|j	d	�|j	d
�|j	d�|j
|_|j��tjd��d
�|_
	t|jd�}i}|D]F}|jd�ddd�\}}t|j!��||j!�<�H|j#�|d|_|d|_n"|j|_|j(|_|j*j-dg�}t/|�dkDxr|dj1�dv|_|j5�d|j6dd��|_|j;�d|j8g}		|j=|	�y#t$r}td|j�d���d}~wwxYw#t$r%}|j?|j8�Yd}~yd}~wwxYw)Nzmega-cmd�	mega-exec�	mega-help�mega-get�
mega-login�mega-logout�mega-ls�
mega-mkdir�mega-put�mega-rm�mega-whoami�HOMEz
/.megav3rc�rzYNo password provided in URL and MEGA configuration file for duplicity does not exist as '�'�=��Username�Password�	no_logoutr)�1�yes�true�/�) �	duplicity�backend�Backend�__init__�_check_binary_exists�hostname�	_hostname�username�os�getenv�_megarc�open�	Exceptionr�	partition�str�strip�close�	_username�	_password�password�
query_args�get�len�lower�
_no_logout�ensure_mega_cmd_running�path�_folder�
mega_login�subprocess_popen�_makedir)
�self�
parsed_url�	conf_file�e�myvars�line�name�var�no_logout_option�cmds
          �B/usr/lib/python3/dist-packages/duplicity/backends/megav3backend.pyr!zMegav3Backend.__init__)s������!�!�*�*�4��<�	
�!�!�*�-��!�!�+�.��!�!�+�.��!�!�*�-��!�!�,�/��!�!�-�0��!�!�)�,��!�!�,�/��!�!�*�-��!�!�)�,��!�!�-�0�$�,�,������&� �i�i��/�0�
�;�D�L�
� ����s�3�	��F�!�
8�� �N�N�3�/��!��4�	��c�'*�3�9�9�;�'7��t�z�z�|�$�
8�
�O�O��#�J�/�D�N�#�J�/�D�N�(�0�0�D�N�'�0�0�D�N�%�0�0�4�4�[�"�E���/�0�1�4�o�;K�A�;N�;T�;T�;V�Zn�;n����$�$�&��:�?�?�1�2�.�/�0���	
�����$�,�,�'��	(��!�!�#�&��=�
�&�4�48�L�L�>��D����
��>�	(��M�M�$�,�,�'�'��	(�s0�!I)�J�)	J�2J�J�	K�J<�<Kc�t�	tjd|g�y#t$r}td|�d���d}~wwxYw)zGChecks that a specified command exists in the running user command path�whichz	Command 'zw' not found, make sure 'MEGAcmd' tools (https://mega.nz/cmd) is properly installed and in the running user command pathN)�
subprocess�check_outputr*r)r=rFr@s   rGr"z"Megav3Backend._check_binary_existsbsG��	��#�#�W�c�N�3���	�"��C�5�!7�8��
��	�s��	7�2�7c��	tjdtjtj��j�y#t$rtd��wxYw)z=Trigger any mega command to ensure mega-cmd server is runningr)�stdout�stderrzCannot execute mega commandN)rJ�run�DEVNULL�check_returncoder*r�r=s rGr7z%Megav3Backend.ensure_mega_cmd_runningnsQ��	B��N�N��!�)�)�!�)�)�
��� ���	B�"�#@�A�A�	B�s�AA�Ac���|j�dd|g}	|j|�y#t$r5}t|�}d|vrt	d|�d���t	d|�d|�d���d}~wwxYw)	z5Creates a remote directory (recursively if necessary)r
z-pzFolder already existszFolder 'zp' could not be created on MEGA because it already exists. Use another path or remove the folder in MEGA manuallyz"' could not be created, reason : 'rN)r:r;r*r,r)r=r8rFr@�	error_strs     rGr<zMegav3Backend._makedirys���	
�����T�4�(��
	`��!�!�#�&���	`��A��I�&�)�3�&��t�f�%M�N���
'��$��7Y�Z[�Y\�\]�'^�_�_��	`�s�)�	A'�0A"�"A'c���	|j|j��|j|j	�j�|j���y#t$rY�IwxYw)zwUploads file to the specified remote folder (tries to delete it first to make
        sure the new one can be uploaded))�
local_file�remote_fileN)�delete�decoder*�upload�
get_canonical)r=�source_path�remote_filenames   rG�_putzMegav3Backend._put�sd��	��K�K��.�.�0�1�	
���"�0�0�2�9�9�;�'�.�.�0�	�	
���	��	�s�A�	A+�*A+c�v�|j|j�|jj���y)z-Downloads file from the specified remote path)rWrVN)�downloadrYrC)r=r]�
local_paths   rG�_getzMegav3Backend._get�s1��	
�
�
�'�.�.�0�!���-�-�/�	�	
�c�&�|jd��S)z(Lists files in the specified remote pathT)�
files_only)�folder_contentsrRs rG�_listzMegav3Backend._list�s���#�#�t�#�4�4rcc�D�|j|j���y)z+Deletes file from the specified remote path)rWN)rXrY)r=�filenames  rG�_deletezMegav3Backend._delete�s��	
������ 1��2rcc�n�|jsdg}|j|�ddg}|j|�y)z/Function called when backend is done being usedrr�exitN)r6r;)r=rFs  rG�_closezMegav3Backend._close�s8����� �/�C��!�!�#�&��F�#�����c�"rcc���	tjddd��}|j�|jj	�jd�dj
�}||jk7rtd��y	#tj$r|j�td��t$r�}|j�|j�|_d
|j|jg}	tj|tj��j�n0#t$r$}|j�td|�d
���d	}~wwxYwYd	}~y	d	}~wwxYw)z0Helper function to check existing session existsr�T)�timeout�capture_output�:���zUsername is not matchz<Timed out while trying to determine if a MEGA session existsNr
)rNz#Could not log in to MEGA, error : 'r)rJrOrQrMrY�splitr-r/r*�TimeoutExpiredrmrr0�get_passwordrP)r=�result�current_usernamer@rFs     rGr:zMegav3Backend.mega_login�s8��
	S��^�^���#��F�

�#�#�%�%�}�}�3�3�5�;�;�C�@��D�J�J�L���4�>�>�1�� 7�8�8�2���(�(�	c��K�K�M�"�#a�b�b��	S��~�~�%�!%�!2�!2�!4����������@�C�
S�����%�-�-��#�"�$���
S����
�&�)L�Q�C�q�'Q�R�R��
S��%��	S�s<�A<A?�?6E�5:E�03D$�#E�$	E�-E�E�E�Ec�(�dd|jg}|j�tj|�}|j	�jd�}|r7|D�cgc],}t
jd|�s�|j�d��.}}|Scc}w)zHLists contents of a remote MEGA path, optionally ignoring subdirectoriesrz-l�
z^-�)r9r:rJrKrYrt�re�search)r=rerF�files�fs     rGrfzMegav3Backend.folder_contents�s~���$����-�������'�'��,������$�$�T�*���+0�G�a�B�I�I�d�A�4F�Q�W�W�Y�q�\�G�E�G����Hs�B�6Bc�n�d|j�d|��|g}|j�|j|�y)z(Downloads a file from a remote MEGA pathr	rN�r9r:r;)r=rWrVrFs    rGr`zMegav3Backend.download�s7���d�l�l�^�1�[�M�:�J�G���������c�"rcc���d||j�d|��g}|j�	|j|�y	#t$r5}t	|�}d|vrtd|�d���td|�d|�d���d	}~wwxYw)
z$Uploads a file to a remote MEGA pathrrzReached storage quotaz1MEGA account over quota, could not write file : 'zD' . Upgrade your storage at https://mega.nz/pro or remove some data.zFailed writing file 'z' to MEGA, reason : 'rN)r9r:r;r*r,r)r=rVrWrFr@rTs      rGrZzMegav3Backend.upload�s����:�$�,�,��q��
�'F�G������
	g��!�!�#�&���	g��A��I�&�)�3�&�G��}�UW�X���
'�)>�{�m�K`�ab�`c�cd�'e�f�f��	g�s�8�	A6�0A1�1A6c�n�dd|j�d|��g}|j�|j|�y)z&Deletes a file from a remote MEGA pathrz-frNr�)r=rWrFs   rGrXzMegav3Backend.delete�s7���$�4�<�<�.��+�� ?�@���������c�"rcN)F)�__name__�
__module__�__qualname__�__doc__r!r"r7r<r^rbrgrjrmr:rfr`rZrX�rcrGrrsT��B�7(�r
�	B�`�"
�
�5�
3�
#�S�@
�#�g�"#rcr�megav3)
r&r|rJ�duplicity.backendr�duplicity.errorsrrr r�register_backend�uses_netloc�extendr�rcrG�<module>r�se��,
�	���-�a#�I�%�%�-�-�a#�H
���"�"�8�]�;�	�����$�$�h�Z�0rc

Zerion Mini Shell 1.0