Mini Shell

Direktori : /lib64/python3.6/site-packages/parted/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/parted/__pycache__/disk.cpython-36.pyc

3

�XZ�@�
@s�ddlZddlZddlmZddlmZGdd�de�ZiZej	�Z
e
ee
j<x<yej	e
�Z
e
ee
j<WqPee
ejfk
r�PYqPXqPWiZejd�Zeje�ee<dZx*er�eje�Zes�dZq�eje�ee<q�WdS)�N)�
CachedList)�localeCc@sFeZdZdZedbdd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
eedd���Zeedd���Z
eedd���Zeedd���Zeedd���Zeedd���Zeedd���Zedd��Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*�d+d*��Zed,d-��Zed.d/��Zed0d1��Zed2d3��Zed4d5��Zed6d7��Zed8d9��Z edcd:d;��Z!eddd<d=��Z"ed>d?��Z#ed@dA��Z$ededBdC��Z%edfdDdE��Z&edgdFdG��Z'edHdI��Z(edJdK��Z)edLdM��Z*dNdO�Z+dPdQ�Z,dRdS�Z-dTdU�Z.dVdW�Z/edXdY��Z0edZd[��Z1ed\d]��Z2ed^d_��Z3d`da�Z4dS)h�Diskz�Disk()

       A Disk object describes a type of device in the system.  Disks
       can hold partitions.  A Disk is a basic operating system-specific
       object.Ncsn|r.|�_|dkr&tj�jjd��_qX|�_n*|dkrBtjd��ntj|j���_|�_t	�fdd���_
dS)z�Create 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)Z	PedDevicezno device specifiedcs�j�S)N)�_Disk__getPartitions�)�selfr�/usr/lib64/python3.6/disk.py�<lambda>8szDisk.__init__.<locals>.<lambda>)�_Disk__disk�partedZDeviceZdev�_device�
DiskException�_pedrZgetPedDevicer�_partitions)r�device�PedDiskr)rr�__init__%sz
Disk.__init__cCsnddl}t|j�t|j�kr dS|jj|j|j�}x6yt|�\}}||krNdSWq4tk
rddSXq4WdS)NrFT)�six�len�
partitionsZmoves�zip�next�
StopIteration)r�otherrZpartIter�left�rightrrr�
_hasSameParts:szDisk._hasSamePartscCs|j|�S)N)�__ne__)rrrrr�__eq__IszDisk.__eq__cCs(t||j�sdS|j|jkp&|j|�S)NT)�
isinstance�	__class__rr)rrrrrrLszDisk.__ne__c	Cs*d|j|j|j|j|j|j|jd�}|S)Nz�parted.Disk instance --
  type: %(type)s  primaryPartitionCount: %(primaryCount)s
  lastPartitionNumber: %(last)s  maxPrimaryPartitionCount: %(max)s
  partitions: %(partitions)s
  device: %(device)r
  PedDisk: %(ped)r)�typeZprimaryCountZlast�maxrrZped)r!�primaryPartitionCount�lastPartitionNumber�maxPrimaryPartitionCountrrr
)r�srrr�__str__RszDisk.__str__cCsZg}|j�}xH|rT|jtj@s6|jtj@s6|jtj@r@|j�}q|j|�|j�}qW|S)z�Construct 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.)�getFirstPartitionr!r�PARTITION_FREESPACEZPARTITION_METADATAZPARTITION_PROTECTEDZ
nextPartition�append)rr�	partitionrrrZ__getPartitions_s
zDisk.__getPartitionscCs
|jj�S)z.The number of primary partitions on this disk.)r
Zget_primary_partition_count)rrrrr#rszDisk.primaryPartitionCountcCs
|jj�S)z:The last assigned partition number currently on this disk.)r
Zget_last_partition_num)rrrrr$xszDisk.lastPartitionNumbercCs
|jj�S)z>The maximum number of primary partitions allowed on this disk.)r
Zget_max_primary_partition_count)rrrrr%~szDisk.maxPrimaryPartitionCountcCs
|jj�S)z6The maximum number of partitions allowed on this disk.)r
Z!get_max_supported_partition_count)rrrr�maxSupportedPartitionCount�szDisk.maxSupportedPartitionCountcCs|jj�}tj|d�S)z"Partition start address Alignment.)ZPedAlignment)r
Zget_partition_alignmentrZ	Alignment)rZ	alignmentrrr�partitionAlignment�s
zDisk.partitionAlignmentcCs
|jj�S)z4Max Partition Length the disk's label can represent.)r
Zmax_partition_length)rrrr�maxPartitionLength�szDisk.maxPartitionLengthcCs
|jj�S)z:Max Partition Start Sector the disk's label can represent.)r
Zmax_partition_start_sector)rrrr�maxPartitionStartSector�szDisk.maxPartitionStartSectorcCs|jj|�S)z�Get 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
Zget_flag)r�flagrrr�getFlag�szDisk.getFlagcCs|jj|d�S)z�Set the flag on this disk.  On error, an Exception will be raised.
           See getFlag() for more help on working with disk flags.�)r
�set_flag)rr0rrr�setFlag�szDisk.setFlagcCs|jj|d�S)z�Unset the flag on this disk.  On error, an Exception will be raised.
           See getFlag() for more help on working with disk flags.r)r
r3)rr0rrr�	unsetFlag�szDisk.unsetFlagcCs|jj|�S)zJReturn True if flag is available on this Disk, False
           otherwise.)r
Zis_flag_available)rr0rrr�isFlagAvailable�szDisk.isFlagAvailablecCs|jS)z.The list of partitions currently on this disk.)r)rrrrr�szDisk.partitionscCs|jS)z7The underlying Device holding this disk and partitions.)r)rrrrr�szDisk.devicecCs
|jjjS)N)r
r!�name)r&rrrr	�sz
Disk.<lambda>cCst|jdtj|�S)Nr!)�setattrr
r�diskType)r&�vrrrr	�scCst|jj�d�S)zMake a deep copy of this Disk.)r)rr
�	duplicate)rrrrr;�szDisk.duplicatecCs
|jj�S)z<Closes the Disk ensuring all outstanding writes are flushed.)r
�destroy)rrrrr<�szDisk.destroycCs|jj�|jj�S)z�Writes 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
�commit)rrrrr>�s
zDisk.commitcCs|jj�|jj�S)zbWrite the changes made to the in-memory description of a
           partition table to the device.)rr=r
Z
commit_to_dev)rrrr�commitToDevice�s
zDisk.commitToDevicecCs|jj�|jj�S)zZTell the operating system kernel about the partition table
           layout of this Disk.)rr=r
Zcommit_to_os)rrrr�
commitToOS�s
zDisk.commitToOScCs
|jj�S)z;Perform a sanity check on the partition table of this Disk.)r
�check)rrrrrA�sz
Disk.checkcCs|jjj|�S)z7Check that the disk type supports the provided feature.)r
r!Z
check_feature)rZfeaturerrr�supportsFeature�szDisk.supportsFeaturecCsj|r|jj|j�|j��}n |s,tjd��n|jj|j��}|rbtj|j�jd�|_|j	j
�dSdSdS)z;Add a new Partition to this Disk with the given Constraint.z$no partition or constraint specified)�PedGeometryTFN)r
Z
add_partition�getPedPartition�getPedConstraintrr
�Geometry�geomZgeometryrr=)rr+�
constraint�resultrrr�addPartition�s
zDisk.addPartitioncCs4|stjd��|jj|j��r,|jj�dSdSdS)aRemoves 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.zno partition specifiedTFN)rr
r
Zremove_partitionrDrr=)rr+rrr�removePartitions

zDisk.removePartitioncCs&|jj|j��r|jj�dSdSdS)z�Removes specified Partition from this Disk under the same
           conditions as removePartition(), but also destroy the
           removed Partition.TFN)r
Zdelete_partitionrDrr=)rr+rrr�deletePartitions
zDisk.deletePartitioncCs |jj�r|jj�dSdSdS)z1Removes and destroys all Partitions in this Disk.TFN)r
Z
delete_allrr=)rrrr�deleteAllPartitionss

zDisk.deleteAllPartitionscCsF|s|rtjd��|s"|r,tjd��|jj|j�|j�||�S)z�Sets 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.z$no partition or constraint specifiedz"no start or end geometry specified)rr
r
Zset_partition_geomrDrE)rr+rH�start�endrrr�setPartitionGeometry&s

zDisk.setPartitionGeometrycCs<|stjd��|r(|jj|j�|j��S|jj|j��SdS)zWGrow the Partition's Geometry to the maximum possible subject
           to Constraint.zno partition specifiedN)rr
r
Zmaximize_partitionrDrE)rr+rHrrr�maximizePartition6s

zDisk.maximizePartitioncCsL|stjd��|r0tj|jj|j�|j��d�Stj|jj|j��d�SdS)zcGet the maximum Geometry the Partition can be grown to,
           subject to the given Constraint.zno partition specified)rCN)rr
rFr
Zget_max_partition_geometryrDrE)rr+rHrrr�calculateMaxPartitionGeometryCs

z"Disk.calculateMaxPartitionGeometrycCs|jj�}|r|jj�|S)z�Reduce 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
Zminimize_extended_partitionrr=)r�retrrr�minimizeExtendedPartitionOs

zDisk.minimizeExtendedPartitioncCstj||jj|�d�S)z�Returns 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
Zget_partition_by_sector)rZsectorrrr�getPartitionBySector[szDisk.getPartitionBySectorc
Cs$ytj||jj�d�SdSdS)z4Return the extended Partition, if any, on this Disk.)rUrVN)rrWr
Zextended_partition)rrrr�getExtendedPartitionbszDisk.getExtendedPartitioncs�fdd�|jD�S)Ncsg|]}�|�r|�qSrr)�.0�part)�fnrr�
<listcomp>lsz+Disk.__filterPartitions.<locals>.<listcomp>)r)rr\r)r\rZ__filterPartitionskszDisk.__filterPartitionscCs|jdd��S)z1Return a list of logical Partitions on this Disk.cSs|jo|jtj@S)N)�activer!rZPARTITION_LOGICAL)�prrrr	psz+Disk.getLogicalPartitions.<locals>.<lambda>)�_Disk__filterPartitions)rrrr�getLogicalPartitionsnszDisk.getLogicalPartitionscCs|jdd��S)z=Return a list of primary (or normal) Partitions on this Disk.cSs|jtjkS)N)r!rZPARTITION_NORMAL)r_rrrr	tsz+Disk.getPrimaryPartitions.<locals>.<lambda>)r`)rrrr�getPrimaryPartitionsrszDisk.getPrimaryPartitionscCs|jdd��S)z:Return a list of RAID (or normal) Partitions on this Disk.cSs|jo|jtj�S)N)r^r1rZPARTITION_RAID)r_rrrr	xsz(Disk.getRaidPartitions.<locals>.<lambda>)r`)rrrr�getRaidPartitionsvszDisk.getRaidPartitionscCs|jdd��S)z>Return a list of physical volume-type Partitions on this Disk.cSs|jo|jtj�S)N)r^r1rZ
PARTITION_LVM)r_rrrr	|sz'Disk.getLVMPartitions.<locals>.<lambda>)r`)rrrr�getLVMPartitionszszDisk.getLVMPartitionscCsHg}|jj�}x4|rB|jtj@r4|jtj|jd��|jj|�}qW|S)zhReturn a list of Geometry objects representing the available
           free space regions on this Disk.)rC)r
�next_partitionr!rr)r*rFrG)r�	freespacer[rrr�getFreeSpaceRegions~s
zDisk.getFreeSpaceRegionscCsHg}|jj�}x4|rB|jtj@r4|jtj||d��|jj|�}qW|S)ziReturn a list of Partition objects representing the available
           free space regions on this Disk.)rUrV)r
rer!rr)r*rW)rrfr[rrr�getFreeSpacePartitions�s
zDisk.getFreeSpacePartitionscCstj||jj�d�S)zUReturn the first Partition object on the disk or None if
           there is not one.)rUrV)rrWr
re)rrrrr(�szDisk.getFirstPartitioncCs"x|jD]}|j|kr|SqWdS)z�Return a Partition object associated with the partition device
           path, such as /dev/sda1.  Returns None if no partition is found.N)r�path)rrir+rrr�getPartitionByPath�s
zDisk.getPartitionByPathcCs|jS)z]Return the _ped.Disk object contained in this Disk.  For internal
           module use only.)r
)rrrr�
getPedDisk�szDisk.getPedDisk)NN)NN)N)NNNN)NN)NN)5�__name__�
__module__�__qualname__�__doc__rrrrrr'r�propertyr#r$r%r,r-r.r/r1r4r5r6rrr!r;r<r>r?r@rArBrJrKrLrMrPrQrRrTrXrYr`rarbrcrdrgrhr(rjrkrrrrrsz
			
rTF)rrZparted.cachedlistrZparted.decoratorsr�objectrr9Zdisk_type_get_nextZ__typer7�
IndexError�	TypeErrorZUnknownTypeExceptionZdiskFlagZdisk_flag_nextZ__flagZdisk_flag_get_nameZ__readFlagsrrrr�<module>s2