HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/duplicity/backends/__pycache__/megav2backend.cpython-310.pyc
o

~�Ha�"�@s�ddlmZddlmZe��ddlmZddlmZddl	Zddl
Z
ddlZddlZGdd�dej
j�Zej
�de�ej
j�dg�dS)	�)�print_function)�standard_library)�util)�BackendExceptionNc@szeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zddd�Z
dd�Zdd�Zdd�ZdS)�
Megav2Backenda� Backend 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 talks to a backend server
         "mega-cmd-server", 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.md c	
Cs�tjj�||�|�d�|�d�|�d�|�d�|�d�|�d�|�d�|�d�|�d	�|j|_|jdur�t�	d
�d|_
zt|j
d�}Wntyb}zt
d
|j
f��d}~wwi}|D]}|�d�ddd�\}}t|���||��<qg|��|d|_|d|_n	|j|_|��|_d|jdd�|_|��d|jg}z|�|�WdSty�}z
|�|j�WYd}~dSd}~ww)N�
mega-login�mega-logoutzmega-cmdzmega-cmd-server�mega-ls�
mega-mkdir�mega-get�mega-put�mega-rm�HOMEz
/.megav2rc�rz\No password provided in URL and MEGA configuration file for duplicity does not exist as '%s'�=��Username�Password�/�)�	duplicity�backend�Backend�__init__�_check_binary_exists�hostname�	_hostname�password�os�getenv�_megarc�open�	Exceptionr�	partition�str�strip�close�	_username�	_password�username�get_password�path�_folder�
mega_login�subprocess_popen�_makedir)	�self�
parsed_url�	conf_file�e�myvars�line�name�var�cmd�r9�B/usr/lib/python3/dist-packages/duplicity/backends/megav2backend.pyr-sN









���


��zMegav2Backend.__init__c
Cs<z
t�d|g�WdSty}ztd|f��d}~ww)zGChecks that a specified command exists in the running user command path�whichz�Command '%s' not found, make sure 'MEGAcmd' tools (https://mega.nz/cmd) is properly installed and in the running user command pathN)�
subprocess�check_outputr"r)r0r8r3r9r9r:r^s���z"Megav2Backend._check_binary_existsc
Csj|��dd|g}z|�|�WdSty4}zt|�}d|vr(td|f��td||f��d}~ww)z5Creates a remote directory (recursively if necessary)r
z-pzFolder already existszzFolder '%s' could not be created on MEGA because it already exists. Use another path or remove the folder in MEGA manuallyz/Folder '%s' could not be created, reason : '%s'N)r-r.r"r$r)r0r+r8r3�	error_strr9r9r:r/hs
���zMegav2Backend._makedircCsDz	|�|���Wn	tyYnw|j|����|��d�dS)z{Uploads 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)r0�source_path�remote_filenamer9r9r:�_putws�zMegav2Backend._putcCs|j|��|j��d�dS)z-Downloads file from the specified remote path)r@r?N)�downloadrBr6)r0rF�
local_pathr9r9r:�_get�szMegav2Backend._getcCs|jdd�S)z(Lists files in the specified remote pathT)�
files_only)�folder_contents)r0r9r9r:�_list�szMegav2Backend._listcCs|j|��d�dS)z+Deletes file from the specified remote path)r@N)rArB)r0�filenamer9r9r:�_delete�szMegav2Backend._deletecCsdg}|�|�dS)z/Function called when backend is done being usedrN)r.)r0r8r9r9r:�_close�szMegav2Backend._closec
Cs�z
tjddd�WdStjytd��tyM}z,d|j|jg}z
tj|tjd�WntyA}ztd|f��d}~wwWYd}~dSd}~ww)	z�Helper function to call from each method interacting with MEGA to make
            sure a session already exists or one is created to start withzmega-session�)�timeoutz<Timed out while trying to determine if a MEGA session existsr)�stderrz&Could not log in to MEGA, error : '%s'N)r<r=�TimeoutExpiredrr"r'r(�DEVNULL)r0r3r8r9r9r:r-�s�����zMegav2Backend.mega_loginFcCsBdd|jg}|��t�|�}|���d�}|rdd�|D�}|S)zHLists contents of a remote MEGA path, optionally ignoring subdirectoriesr	z-l�
cSs$g|]}t�d|�r|��d�qS)z^-�)�re�search�split)�.0�fr9r9r:�
<listcomp>�s$z1Megav2Backend.folder_contents.<locals>.<listcomp>)r,r-r<r=rBrZ)r0rKr8�filesr9r9r:rL�s
zMegav2Backend.folder_contentscCs*d|jd||g}|��|�|�dS)z(Downloads a file from a remote MEGA pathrrN�r,r-r.)r0r@r?r8r9r9r:rH��zMegav2Backend.downloadc
Cstd||jd|g}|��z|�|�WdSty9}zt|�}d|vr-td|f��td||f��d}~ww)z$Uploads a file to a remote MEGA pathrrzReached storage quotazwMEGA account over quota, could not write file : '%s' . Upgrade your storage at https://mega.nz/pro or remove some data.z/Failed writing file '%s' to MEGA, reason : '%s'N)r,r-r.r"r$r)r0r?r@r8r3r>r9r9r:rC�s���zMegav2Backend.uploadcCs*dd|jd|g}|��|�|�dS)z&Deletes a file from a remote MEGA pathr
z-frNr_)r0r@r8r9r9r:rA�r`zMegav2Backend.deleteN)F)�__name__�
__module__�__qualname__�__doc__rrr/rGrJrMrOrPr-rLrHrCrAr9r9r9r:r"s
1


r�megav2)�
__future__r�futurer�install_aliasesrr�duplicity.errorsr�duplicity.backendrr<rXrrr�register_backend�uses_netloc�extendr9r9r9r:�<module>s4