
    XZ@                        d dl Z d dlZd dlmZ d dlmZ  G d de      Zi Z e j                         Z
e
ee
j                  <   	 	  e j                  e
      Z
e
ee
j                  <   ## eee j                  f$ r Y nw xY wi Z e j                   d       Z e j$                  e      ee<   dZer0 e j                   e      ZesdZn e j$                  e      ee<   er/yy)    N)
CachedList)localeCc                      e Zd ZdZed3d       Zd Zd Zd Zd Z	d Z
eed	               Zeed
               Zeed               Zeed               Zeed               Zeed               Zeed               Zed        Zed        Zed        Zed        Zed        Zed        Z ed d       Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z ed3d       Z!ed4d        Z"ed!        Z#ed"        Z$ed5d#       Z%ed3d$       Z&ed3d%       Z'ed&        Z(ed'        Z)ed(        Z*d) Z+d* Z,d+ Z-d, Z.d- Z/ed.        Z0ed/        Z1ed0        Z2ed1        Z3d2 Z4y)6DiskzDisk()

       A Disk object describes a type of device in the system.  Disks
       can hold partitions.  A Disk is a basic operating system-specific
       object.Nc                 >    |rA| _         |0t        j                   j                   j                         _        nN| _        nF|t        j
                  d      t        j                  |j                                _         | _        t         fd       _
        y)zCreate a new Disk object from the device and type specified.  The
           device is a Device object and type is a string matching a key in
           the diskType hash.N)	PedDevicezno device specifiedc                  $     j                         S N)_Disk__getPartitionsselfs   -/usr/lib/python3/dist-packages/parted/disk.py<lambda>zDisk.__init__.<locals>.<lambda>8   s    t/C/C/E     )_Disk__diskpartedDevicedev_deviceDiskException_pedr   getPedDevicer   _partitions)r   devicePedDisks   `  r   __init__zDisk.__init__%   sz    
 !DK~%}}t{{G%^&&'<==))F$7$7$9:DK!DL &&EFr   c                    dd l }t        | j                        t        |j                        k7  ry|j                  j	                  | j                  |j                        }	 	 t        |      \  }}||k7  ry	 # t        $ r Y yw xY w)Nr   FT)sixlen
partitionsmoveszipnextStopIteration)r   otherr   partIterleftrights         r   _hasSamePartszDisk._hasSameParts:   s    t3u'7'7#8899==%2B2BC $Xu5=  ! 
 ! s   #A9 9	BBc                 &    | j                  |       S r
   )__ne__r   r%   s     r   __eq__zDisk.__eq__I   s    ;;u%%%r   c                     t        | |j                        sy| j                  |j                  k7  xs | j                  |       S )NT)
isinstance	__class__r   r)   r,   s     r   r+   zDisk.__ne__L   s9    $0{{ell*K$2D2DU2K.KKr   c           	          d| j                   | j                  | j                  | j                  | j                  | j
                  | j                  dz  }|S )Nzparted.Disk instance --
  type: %(type)s  primaryPartitionCount: %(primaryCount)s
  lastPartitionNumber: %(last)s  maxPrimaryPartitionCount: %(max)s
  partitions: %(partitions)s
  device: %(device)r
  PedDisk: %(ped)r)typeprimaryCountlastmaxr    r   ped)r2   primaryPartitionCountlastPartitionNumbermaxPrimaryPartitionCountr    r   r   )r   ss     r   __str__zDisk.__str__R   sP    " ii1K1K..t7T7T OOt{{[["	" r   c                 F   g }| j                         }|r|j                  t        j                  z  s:|j                  t        j                  z  s|j                  t        j
                  z  r|j                         }j|j                  |       |j                         }|r|S )zConstruct a list of partitions on the disk.  This is called only as
           needed from the self.partitions property, which just happens to be
           a CachedList.)getFirstPartitionr2   r   PARTITION_FREESPACEPARTITION_METADATAPARTITION_PROTECTEDnextPartitionappend)r   r    	partitions      r   __getPartitionszDisk.__getPartitions_   s     
**,	~~ : ::~~ 9 99~~ : ::%335	i(!//1I  r   c                 6    | j                   j                         S )z.The number of primary partitions on this disk.)r   get_primary_partition_countr   s    r   r7   zDisk.primaryPartitionCountr   s     {{6688r   c                 6    | j                   j                         S )z:The last assigned partition number currently on this disk.)r   get_last_partition_numr   s    r   r8   zDisk.lastPartitionNumberx   s     {{1133r   c                 6    | j                   j                         S )z>The maximum number of primary partitions allowed on this disk.)r   get_max_primary_partition_countr   s    r   r9   zDisk.maxPrimaryPartitionCount~   s     {{::<<r   c                 6    | j                   j                         S )z6The maximum number of partitions allowed on this disk.)r   !get_max_supported_partition_countr   s    r   maxSupportedPartitionCountzDisk.maxSupportedPartitionCount   s     {{<<>>r   c                 b    | j                   j                         }t        j                  |      S )z"Partition start address Alignment.)PedAlignment)r   get_partition_alignmentr   	Alignment)r   	alignments     r   partitionAlignmentzDisk.partitionAlignment   s'     KK779	Y77r   c                 6    | j                   j                         S )z4Max Partition Length the disk's label can represent.)r   max_partition_lengthr   s    r   maxPartitionLengthzDisk.maxPartitionLength   s     {{//11r   c                 6    | j                   j                         S )z:Max Partition Start Sector the disk's label can represent.)r   max_partition_start_sectorr   s    r   maxPartitionStartSectorzDisk.maxPartitionStartSector   s     {{5577r   c                 8    | j                   j                  |      S )zGet the value of a particular flag on the disk.  Valid flags
           are the _ped.DISK_* constants.  See _ped.disk_flag_get_name() and
           _ped.disk_flag_get_by_name() for more help working with disk flags.
        )r   get_flagr   flags     r   getFlagzDisk.getFlag   s     {{##D))r   c                 :    | j                   j                  |d      S )zSet the flag on this disk.  On error, an Exception will be raised.
           See getFlag() for more help on working with disk flags.   r   set_flagr\   s     r   setFlagzDisk.setFlag        {{##D!,,r   c                 :    | j                   j                  |d      S )zUnset the flag on this disk.  On error, an Exception will be raised.
           See getFlag() for more help on working with disk flags.r   ra   r\   s     r   	unsetFlagzDisk.unsetFlag   rd   r   c                 8    | j                   j                  |      S )zJReturn True if flag is available on this Disk, False
           otherwise.)r   is_flag_availabler\   s     r   isFlagAvailablezDisk.isFlagAvailable   s     {{,,T22r   c                     | j                   S )z.The list of partitions currently on this disk.)r   r   s    r   r    zDisk.partitions   s     r   c                     | j                   S )z7The underlying Device holding this disk and partitions.)r   r   s    r   r   zDisk.device   s     ||r   c                 B    | j                   j                  j                  S r
   )r   r2   name)r:   s    r   r   zDisk.<lambda>   s    ahhmm00 r   c                 R    t        | j                  dt        j                  |         S )Nr2   )setattrr   r   diskType)r:   vs     r   r   zDisk.<lambda>   s!    wqxxQWY_YhYhijYk?l r   c                 J    t        | j                  j                               S )zMake a deep copy of this Disk.)r   )r   r   	duplicater   s    r   rs   zDisk.duplicate   s     DKK11344r   c                 6    | j                   j                         S )z<Closes the Disk ensuring all outstanding writes are flushed.)r   destroyr   s    r   ru   zDisk.destroy   s     {{""$$r   c                 j    | j                   j                          | j                  j                         S )zWrites in-memory changes to a partition table to disk and
           informs the operating system of the changes.  Equivalent to
           calling self.commitToDevice() then self.commitToOS().)r    
invalidater   commitr   s    r   rx   zDisk.commit   s'    
 	""${{!!##r   c                 j    | j                   j                          | j                  j                         S )zbWrite the changes made to the in-memory description of a
           partition table to the device.)r    rw   r   commit_to_devr   s    r   commitToDevicezDisk.commitToDevice   s'     	""${{((**r   c                 j    | j                   j                          | j                  j                         S )zZTell the operating system kernel about the partition table
           layout of this Disk.)r    rw   r   commit_to_osr   s    r   
commitToOSzDisk.commitToOS   s'     	""${{''))r   c                 6    | j                   j                         S )z;Perform a sanity check on the partition table of this Disk.)r   checkr   s    r   r   z
Disk.check   s     {{  ""r   c                 L    | j                   j                  j                  |      S )z7Check that the disk type supports the provided feature.)r   r2   check_feature)r   features     r   supportsFeaturezDisk.supportsFeature   s     {{--g66r   c                    |r9| j                   j                  |j                         |j                               }n@|st	        j
                  d      | j                   j                  |j                               }|rNt	        j                  |j                         j                        |_        | j                  j                          yy)z;Add a new Partition to this Disk with the given Constraint.$no partition or constraint specifiedPedGeometryTF)r   add_partitiongetPedPartitiongetPedConstraintr   r   Geometrygeomgeometryr    rw   )r   rC   
constraintresults       r   addPartitionzDisk.addPartition   s     [[..y/H/H/J/9/J/J/LNF&&'MNN[[..y/H/H/JKF!'Y=V=V=X=]=]!^IOO&&(r   c                     |st        j                  d      | j                  j                  |j	                               r| j
                  j                          yy)a  Removes specified Partition from this Disk.  NOTE:  If the
           Partition is an extended partition, it must not contain any
           logical partitions.  Also note that the partition is not
           actually destroyed unless you use the deletePartition()
           method.no partition specifiedTF)r   r   r   remove_partitionr   r    rw   r   rC   s     r   removePartitionzDisk.removePartition  sJ     &&'?@@;;''	(A(A(CDOO&&(r   c                     | j                   j                  |j                               r| j                  j	                          yy)zRemoves specified Partition from this Disk under the same
           conditions as removePartition(), but also destroy the
           removed Partition.TF)r   delete_partitionr   r    rw   r   s     r   deletePartitionzDisk.deletePartition  s5    
 ;;''	(A(A(CDOO&&(r   c                 n    | j                   j                         r| j                  j                          yy)z1Removes and destroys all Partitions in this Disk.TF)r   
delete_allr    rw   r   s    r   deleteAllPartitionszDisk.deleteAllPartitions  s*     ;;!!#OO&&(r   c                     |r|st        j                  d      |r|st        j                  d      | j                  j                  |j	                         |j                         ||      S )zSets the Geometry of the specified Partition using the given
           Constraint and start and end sectors.  Note that this method
           does not modify the partition contents, just the partition
           table.r   z"no start or end geometry specified)r   r   r   set_partition_geomr   r   )r   rC   r   startends        r   setPartitionGeometryzDisk.setPartitionGeometry&  se     
&&'MNNC&&'KLL{{--i.G.G.I.8.I.I.K.3S: 	:r   c                     |st        j                  d      |r8| j                  j                  |j	                         |j                               S | j                  j                  |j	                               S )zWGrow the Partition's Geometry to the maximum possible subject
           to Constraint.r   )r   r   r   maximize_partitionr   r   r   rC   r   s      r   maximizePartitionzDisk.maximizePartition6  sl     &&'?@@;;11)2K2K2M2<2M2M2OQ Q ;;11)2K2K2MNNr   c                 F   |st        j                  d      |rLt        j                  | j                  j	                  |j                         |j                                     S t        j                  | j                  j	                  |j                                     S )zcGet the maximum Geometry the Partition can be grown to,
           subject to the given Constraint.r   r   )r   r   r   r   get_max_partition_geometryr   r   r   s      r   calculateMaxPartitionGeometryz"Disk.calculateMaxPartitionGeometryC  s     &&'?@@??t{{/U/UV_VoVoVqs}  tO  tO  tQ  0R  S  S??t{{/U/UV_VoVoVq/rssr   c                 r    | j                   j                         }|r| j                  j                          |S )zReduce the size of the extended partition to a minimum while
           still wrapping its logical partitions.  If there are no logical
           partitions, remove the extended partition.)r   minimize_extended_partitionr    rw   )r   rets     r   minimizeExtendedPartitionzDisk.minimizeExtendedPartitionO  s.    
 kk557OO&&(
r   c                 b    t        j                  | | j                  j                  |            S )zReturns the Partition that contains the sector.  If the sector
           lies within a logical partition, then the logical partition is
           returned (not the extended partition).diskPedPartition)r   	Partitionr   get_partition_by_sector)r   sectors     r   getPartitionBySectorzDisk.getPartitionBySector[  s'    
 T8[8[\b8cddr   c                 p    	 t        j                  | | j                  j                               S #  Y yxY w)z4Return the extended Partition, if any, on this Disk.r   N)r   r   r   extended_partitionr   s    r   getExtendedPartitionzDisk.getExtendedPartitionb  s1    	##DKK<Z<Z<\]]	s   .1 5c                 R    | j                   D cg c]  } ||      s| c}S c c}w r
   )r    )r   fnparts      r   __filterPartitionszDisk.__filterPartitionsk  s     !%=BtH===s   $$c                 &    | j                  d       S )z1Return a list of logical Partitions on this Disk.c                 X    | j                   xr | j                  t        j                  z  S r
   )activer2   r   PARTITION_LOGICALps    r   r   z+Disk.getLogicalPartitions.<locals>.<lambda>p  s    1_affvG_G_>_ r   _Disk__filterPartitionsr   s    r   getLogicalPartitionszDisk.getLogicalPartitionsn  s    &&'_``r   c                 &    | j                  d       S )z=Return a list of primary (or normal) Partitions on this Disk.c                 <    | j                   t        j                  k(  S r
   )r2   r   PARTITION_NORMALr   s    r   r   z+Disk.getPrimaryPartitions.<locals>.<lambda>t  s    6;R;R1R r   r   r   s    r   getPrimaryPartitionszDisk.getPrimaryPartitionsr  s    &&'RSSr   c                 &    | j                  d       S )z:Return a list of RAID (or normal) Partitions on this Disk.c                 \    | j                   xr | j                  t        j                        S r
   )r   r^   r   PARTITION_RAIDr   s    r   r   z(Disk.getRaidPartitions.<locals>.<lambda>x  s    1^aiiH]H]>^ r   r   r   s    r   getRaidPartitionszDisk.getRaidPartitionsv  s    &&'^__r   c                 &    | j                  d       S )z>Return a list of physical volume-type Partitions on this Disk.c                 \    | j                   xr | j                  t        j                        S r
   )r   r^   r   PARTITION_LVMr   s    r   r   z'Disk.getLVMPartitions.<locals>.<lambda>|  s    1]aiiH\H\>] r   r   r   s    r   getLVMPartitionszDisk.getLVMPartitionsz  s    &&']^^r   c                    g }| j                   j                         }|rj|j                  t        j                  z  r/|j                  t        j                  |j                               | j                   j                  |      }|rj|S )zhReturn a list of Geometry objects representing the available
           free space regions on this Disk.r   )r   next_partitionr2   r   r>   rB   r   r   r   	freespacer   s      r   getFreeSpaceRegionszDisk.getFreeSpaceRegions~  sl     	{{))+yy6555  TYY!GH;;--d3D	  r   c                    g }| j                   j                         }|ra|j                  t        j                  z  r&|j                  t        j                  | |             | j                   j                  |      }|ra|S )ziReturn a list of Partition objects representing the available
           free space regions on this Disk.r   )r   r   r2   r   r>   rB   r   r   s      r   getFreeSpacePartitionszDisk.getFreeSpacePartitions  sl     	{{))+yy6555  !1!1t$!OP;;--d3D	  r   c                 `    t        j                  | | j                  j                               S )zUReturn the first Partition object on the disk or None if
           there is not one.r   )r   r   r   r   r   s    r   r=   zDisk.getFirstPartition  s$     T8R8R8TUUr   c                 L    | j                   D ]  }|j                  |k(  s|c S  y)zReturn a Partition object associated with the partition device
           path, such as /dev/sda1.  Returns None if no partition is found.N)r    path)r   r   rC   s      r   getPartitionByPathzDisk.getPartitionByPath  s.      	!I~~%  	! r   c                     | j                   S )z]Return the _ped.Disk object contained in this Disk.  For internal
           module use only.)r   r   s    r   
getPedDiskzDisk.getPedDisk  s     {{r   )NNr
   )NNNN)5__name__
__module____qualname____doc__r   r   r)   r-   r+   r;   r   propertyr7   r8   r9   rM   rS   rV   rY   r^   rc   rf   ri   r    r   r2   rs   ru   rx   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r=   r   r    r   r   r   r      sO   
 G G(&L& 9  9 4  4 =  = ?  ? 8  8
 2  2 8  8 * * - -
 - -
 3 3
       02lmD5 5 % % $ $ + + * * # # 7 7  "       : : 
O 
O 	t 	t 	 	 e e  >aT`_     V V
  r   r   TF)r   r   parted.cachedlistr   parted.decoratorsr   objectr   rp   disk_type_get_next__typerm   
IndexError	TypeErrorUnknownTypeExceptiondiskFlagdisk_flag_next__flagdisk_flag_get_name__readFlagsr   r   r   <module>r      s  2   ( %P6 Pf 	 	 	 	" 
(((0 &  	4#<#<=  			Q	*4**62  T  (F24226: s   !A& &A;:A;