%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/DistUpgrade/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/DistUpgrade/__pycache__/apt_btrfs_snapshot.cpython-312.pyc

�

9_f�&���ddlmZmZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZGd�de
�ZGd�de�ZGd	�d
e�ZGd�de�ZGd
�de�ZGd�de�ZGd�de�Zy)�)�print_function�unicode_literalsN)�find_executable)�gettextc��eZdZy)�AptBtrfsSnapshotErrorN��__name__�
__module__�__qualname__���@/usr/lib/python3/dist-packages/DistUpgrade/apt_btrfs_snapshot.pyrr!���rrc��eZdZy)�AptBtrfsNotSupportedErrorNr	r
rrrr%rrrc��eZdZy)�AptBtrfsRootWithNoatimeErrorNr	r
rrrr)rrrc�.�eZdZdZed��Zdd�Zd�Zy)�
FstabEntryz a single fstab entry line c�\�|jd�dj�}t|dd�S)N�#r�)�	partition�splitr)�cls�line�argss   r�	from_linezFstabEntry.from_line/s3���~�~�c�"�1�%�+�+�-���4��!�9�%�%rc�X�||_||_||_||_||_||_y�N��fs_spec�
mountpoint�fstype�options�dump�passno)�selfr#r$r%r&r'r(s       r�__init__zFstabEntry.__init__7s,�����$�����������	���rc
��d|j�d|j�d|j�d|j�d|j�d|j
�d�
S)Nz
<FstabEntry 'z' 'z'>r"�r)s r�__repr__zFstabEntry.__repr__@s2���L�L�$�/�/�4�;�;��L�L�$�)�)�T�[�[�2�	2rN)rr)r
rr�__doc__�classmethodrr*r-r
rrrr-s!��%��&��&��2rrc�$��eZdZdZd�fd�	Z�xZS)�Fstabz a list of FstabEntry items c�"��tt|��t|�5}d�|D�D]@}|dk(s|j	d�r�	t
j
|�}|j|��B	ddd�y#t$rY�XwxYw#1swYyxYw)Nc3�<K�|]}|j����y�wr!)�strip)�.0rs  r�	<genexpr>z!Fstab.__init__.<locals>.<genexpr>Ls����!F�4�$�*�*�,�!F�s��r)	�superr1r*�open�
startswithrr�
ValueError�append)r)�fstab�
fstab_file�
stripped_line�entry�	__class__s     �rr*zFstab.__init__Hs����
�e�T�#�%�
�%�[�	#�J�!F�:�!F�
#�
� �B�&�-�*B�*B�3�*G���&�0�0��?�E����E�"�
#�	#�	#��"�����
	#�	#�s/�$B�A6�B�6	B�?B�B�B�B�z
/etc/fstab)r
rrr.r*�
__classcell__)rAs@rr1r1Fs���&�#�#rr1c�(�eZdZdZd�Zd�Zd�Zd�Zy)�LowLevelCommandszi lowlevel commands invoked to perform various tasks like
        interact with mount and btrfs tools
    c�<�tjd||g�}|dk(S)N�mountr��
subprocess�call)r)r#r$�rets    rrGzLowLevelCommands.mountZs ���o�o�w���<�=���a�x�rc�:�tjd|g�}|dk(S)N�umountrrH)r)r$rKs   rrMzLowLevelCommands.umount^s���o�o�x��4�5���a�x�rc�@�tjddd||g�}|dk(S)N�btrfs�	subvolume�snapshotrrH)r)�source�destrKs    r�btrfs_subvolume_snapshotz)LowLevelCommands.btrfs_subvolume_snapshotbs)���o�o�w��Z�%�t�-�.���a�x�rc�>�tjddd|g�}|dk(S)NrOrP�deleterrH)r)rQrKs   r�btrfs_delete_snapshotz&LowLevelCommands.btrfs_delete_snapshotgs"���o�o�w��X�x�H�I���a�x�rN)r
rrr.rGrMrTrWr
rrrErEVs������
rrEc��eZdZdZdZedzZdd�Zd�Zd�Zdd�Z	d�Z
d	�Zd
�Zdd�Z
dd�Zd
�Zd�Zd�Zd�Zd�Zdd�Zd�Zy)�AptBtrfsSnapshotz? the high level object that interacts with the snapshot system z@apt-snapshot-z	old-root-c�P�t|�|_t�|_d|_yr!)r1r=rE�commands�_btrfs_root_mountpoint)r)r=s  rr*zAptBtrfsSnapshot.__init__ts���5�\��
�(�*��
�&*��#rc�B�td�sy|j�}|duS)zx verify that the system supports apt btrfs snapshots
            by checking if the right fs layout is used etc
        rOFN)r�%_get_supported_btrfs_root_fstab_entry�r)r@s  r�snapshots_supportedz$AptBtrfsSnapshot.snapshots_supportedys(�� ��(���:�:�<���D� � rc��|jD]4}|jdk(s�|jdk(s�#d|jvs�2|cSy)z4 return the supported btrfs root FstabEntry or None �/rOzsubvol=@N)r=r$r%r&r_s  rr^z6AptBtrfsSnapshot._get_supported_btrfs_root_fstab_entry�sE���Z�Z�	�E��$�$��+��L�L�G�+��%�-�-�/���	�rc�`�|jD]}|j|k(s�|jcSy)z4 return the device or UUID for the given mountpoint N)r=r$r#)r)r$r=r@s    r�_uuid_for_mountpointz%AptBtrfsSnapshot._uuid_for_mountpoint�s2���Z�Z�	%�E����:�-��}�}�$�	%�rc��|jd�}tjd��}|jj	||�sy||_|j
S)Nrbzapt-btrfs-snapshot-mp-)�prefix)rd�tempfile�mkdtempr[rGr\)r)�uuidr$s   r�mount_btrfs_root_volumez(AptBtrfsSnapshot.mount_btrfs_root_volume�sN���(�(��-���%�%�-E�F�
��}�}�"�"�4��4��&0��#��*�*�*rc��|jj|j�}tj|j�d|_|Sr!)r[rMr\�os�rmdir)r)�ress  r�umount_btrfs_root_volumez)AptBtrfsSnapshot.umount_btrfs_root_volume�s;���m�m�"�"�4�#>�#>�?��
����,�,�-�&*��#��
rc��tjj�jd��jt	d��S)Nr)�microsecond�_)�datetime�now�replace�	isoformat�strr,s r�_get_now_strzAptBtrfsSnapshot._get_now_str�s9��� � �$�$�&�.�.�1�.�=�G�G���H��	rc��|j�}|j�}tjj	|d�}tjj	||j
|z|z�}tjj
|�rttd�|fz�y|jj||�}|j�|S)N�@zDINFO: snapshot directory '%s' already exists, not creating duplicateT)rjrxrl�path�join�SNAP_PREFIX�exists�printrrr[rTro)r)�additional_prefix�mp�snap_idrR�targetrns       r�create_btrfs_root_snapshotz+AptBtrfsSnapshot.create_btrfs_root_snapshot�s���
�
)�
)�
+���#�#�%�������b�#�&�������b�$�"2�"2�5F�"F�%�#&�'���7�7�>�>�&�!��!�-�.�17�	�:�
;���-�-�8�8���H�C��)�)�+��Jrc	��g}|dk7r4|j�}|s
t��d|jvr
t��|dk(rt	j�}|j�}t
j|�D]t}|j|j�s�tjjtjj||dd��}||ks�d|j|��v|j�|S)z� get the list of available snapshot
            If "older_then" is given (in unixtime format) it will only include
            snapshots that are older then the given date)
        r�noatime�etcr=)r^rr&r�timerjrl�listdirr:r}r{�getatimer|r<ro)r)�
older_than�resultr@r��e�atimes       r�get_btrfs_root_snapshots_listz.AptBtrfsSnapshot.get_btrfs_root_snapshots_list�s���
����?��>�>�@�E��/�1�1��E�M�M�)�2�4�4���?�����J�
�
)�
)�
+�����B��	%�A��|�|�D�,�,�-����(�(������b�!�U�G�)L�M���:�%��M�M�!�$�
	%�	
�%�%�'��
rc�j�td�tdj|j���y)NzAvailable snapshots:�  
T)rr|r�r,s r�print_btrfs_root_snapshotsz+AptBtrfsSnapshot.print_btrfs_root_snapshots�s(��
�$�%�
�f�k�k�$�<�<�>�?�@�rc��tj�}|jd�std��t|dd�}||dzdzdzz
S)N�dz&Please specify time in days (e.g. 10d)�����<)r��endswith�	Exception�int)r)�timefmtrt�dayss    r�_parse_older_than_to_unixtimez.AptBtrfsSnapshot._parse_older_than_to_unixtime�sO���i�i�k������$��D�E�E��7�3�B�<� ���d�R�i�"�n�r�)�*�*rc���|j|�}	td|z�tdj|j|����y#t$r"t
jjd�YywxYw)Nz$Available snapshots older than '%s':r��r��6Error: fstab option 'noatime' incompatible with optionFT)r�rr|r�r�sys�stderr�write)r)r��older_than_unixtimes   r�%print_btrfs_root_snapshots_older_thanz6AptBtrfsSnapshot.print_btrfs_root_snapshots_older_than�s��"�@�@��I��	��8�7�B�C��&�+�+�d�@�@�.�A�0�1�
2���	,�	��J�J���+�
,��	�s�8A�(A7�6A7c���d}|j|�}	|j|��D]}||j|�z}�	|S#t$r"tj
j
d�YywxYw)NTr�r�F)r�r��delete_snapshotrr�r�r�)r)r�rnr��snaps     r�%clean_btrfs_root_snapshots_older_thanz6AptBtrfsSnapshot.clean_btrfs_root_snapshots_older_than�s�����"�@�@��I��	��:�:�2�;�4�
2���t�+�+�D�1�1��
2��
��	,�	��J�J���&�
'��	�s�+A�(A.�-A.c�(�|j|�}|Sr!)�set_default)r)�
snapshot_namerns   r�command_set_defaultz$AptBtrfsSnapshot.command_set_default�s�����}�-���
rc�0�|j�}tjj||�}tjj	|�r�|jd�r�|dk7r�tjj|d�}tjj||j|j�z�}tj||�tj||�td|z�ntd�|j�y)z set new default rzz@Default changed to %s, please reboot for changes to take effect.z_You have selected an invalid snapshot. Please make sure that it exists, and that it is not "@".T)rjrlr{r|�isdirr:�
BACKUP_PREFIXrx�renamerro)r)r��backupr��new_root�default_roots      rr�zAptBtrfsSnapshot.set_default�s���
�
)�
)�
+���7�7�<�<��M�2�����
�
�h�'��(�(��-���$��7�7�<�<��C�0�L��W�W�\�\�"�d�&8�&8�4�;L�;L�;N�&N�O�F��I�I�l�F�+��I�I�h��-���+�,�
-�
�>�
?��%�%�'�rc��|j�}|jjtjj||��}|j
�|Sr!)rjr[rWrlr{r|ro)r)r�r�rns    rr�z AptBtrfsSnapshot.delete_snapshotsG��
�
)�
)�
+���m�m�1�1��G�G�L�L��]�+�-���%�%�'��
rNrB)r7)r)T)r
rrr.r}r�r*r`r^rdrjrorxr�r�r�r�r�r�r�r�r�r
rrrYrYlsf��I�#�K��+�-�M�+�
!���+���� �8�
+�
����(rrY)�
__future__rrrsrlrIr�r�rg�distutils.spawnrrrrr�rrr�objectr�listr1rErYr
rr�<module>r�sz��&8��	��
���+� �	�I�	�	� 5�	�	�#8�	�2��2�2
#�D�
#� �v��,h�v�hr

Zerion Mini Shell 1.0