
    r(b1                     |    d dl Z e j                  dk\  reZd dlZd dlmZ d dlZd dlZd dl	Z	d dl
mZ  G d de      Zy)    N)   )Decimal)localeCc                      e Zd ZdZed/d       Zd Zd Zd Ze	d        Z
e	d        Ze	d	        Ze	d
        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Ze	d        Zd Zed        Zed        Zed        Zed        Zed        Zed        Z ed        Z!ed        Z"ed         Z#ed0d!       Z$ed"        Z%ed#        Z&ed$        Z'ed%        Z(ed&        Z)d1d'Z*ed2d(       Z+ed)        Z,e	ed*               Z-e	ed+               Z.e	ed,               Z/e	ed-               Z0d. Z1y)3Deviceab  Device()

       Device represents a physical piece of hardware in the system, e.g. a
       disk.  A Device should be considered a low-level and operating system
       specific interface to the hardware.

       A number of read-only properties of the Device are available.

       For information on the individual methods, see help(Device.METHODNAME)Nc                 z    |r|| _         y|t        j                  |      | _         yt        j                  d      )zCreate a new Device object based on the specified path or the
           already existing _ped.Device object.  You must provide either a
           path (e.g., "/dev/sda") or an existing _ped.Device object, but
           not both.Nzno path or PedDevice specified)_Device__device_ped
device_getpartedDeviceException)selfpath	PedDevices      //usr/lib/python3/dist-packages/parted/device.py__init__zDevice.__init__1   s6     %DM OOD1DM(()IJJ    c                 &    | j                  |       S N)__ne__r   others     r   __eq__zDevice.__eq__?   s    ;;u%%%r   c                    t        | |j                        sy| j                  |j                  k7  xsO | j                  |j                  k7  xs4 | j                  |j                  k7  xs | j
                  |j
                  k7  S )NT)
isinstance	__class__modelr   typelengthr   s     r   r   zDevice.__ne__B   se    $0zzU[[(}DII,C}tyyTYT^T^G^}bfbmbmqvq}q}b}}r   c                 H    |j                   |j                  |j                  fS r   )	cylindersheadssectors)r   geometrys     r   __getCHSzDevice.__getCHSH   s    ""HNNH4D4DEEr   c                 .    | j                   j                  S )z%Model name and vendor of this device.)r	   r   r   s    r   r   zDevice.modelK   s     }}"""r   c                 .    | j                   j                  S )z5Filesystem node path of this device (e.g., /dev/sda).)r	   r   r'   s    r   r   zDevice.pathP        }}!!!r   c                 .    | j                   j                  S )zqType of this device.  An integer constant corresponding
           to one of the parted.DEVICE_* values.
        )r	   r   r'   s    r   r   zDevice.typeU   s    
 }}!!!r   c                 .    | j                   j                  S )z'Sector size (in bytes) for this device.)r	   sector_sizer'   s    r   
sectorSizezDevice.sectorSize\   s     }}(((r   c                 .    | j                   j                  S )zPhysical sector size (in bytes) for this device.  Not always
           the same as sectorSize, but is a multiple of sectorSize.
        )r	   phys_sector_sizer'   s    r   physicalSectorSizezDevice.physicalSectorSizea   s    
 }}---r   c                 .    | j                   j                  S )z#The size of this device in sectors.)r	   r   r'   s    r   r   zDevice.lengthh   s     }}###r   c                 .    | j                   j                  S )z@How many times the open() method has been called on this device.)r	   
open_countr'   s    r   	openCountzDevice.openCountm   s     }}'''r   c                 @    t        | j                  j                        S )zWTrue if the device is currently in read-only mode, False
           otherwise.
        )boolr	   	read_onlyr'   s    r   readOnlyzDevice.readOnlyr   s    
 DMM++,,r   c                 @    t        | j                  j                        S )a  True if external access mode is currently activated on this
           device, False otherwise.  External access mode has to be used
           if you want to use an external command on the device while
           you are currently using it in pyparted.
        )r6   r	   external_moder'   s    r   externalModezDevice.externalModey   s     DMM//00r   c                 @    t        | j                  j                        S )z4True if the device is marked dirty, False otherwise.)r6   r	   dirtyr'   s    r   r=   zDevice.dirty   s     DMM''((r   c                 @    t        | j                  j                        S )z9True if the device is marked boot dirty, False otherwise.)r6   r	   
boot_dirtyr'   s    r   	bootDirtyzDevice.bootDirty   s     DMM,,--r   c                 .    | j                   j                  S )zThe host value of this device.)r	   hostr'   s    r   rB   zDevice.host   r)   r   c                 .    | j                   j                  S )zThe did value of this device.)r	   didr'   s    r   rD   z
Device.did   s     }}   r   c                 6    | j                   j                         S )z-True if this device is busy, False otherwise.)r	   is_busyr'   s    r   busyzDevice.busy        }}$$&&r   c                 L    | j                  | j                  j                        S )zA 3-tuple representing the hardware geometry of this device.
           The tuple is in order of cylinders, heads, and sectors.
        )_Device__getCHSr	   hw_geomr'   s    r   hardwareGeometryzDevice.hardwareGeometry   s    
 }}T]]2233r   c                 L    | j                  | j                  j                        S )zA 3-tuple representing the BIOS geometry of this device.
           The tuple is in order of cylinders, heads, and sectors.
        )rJ   r	   	bios_geomr'   s    r   biosGeometryzDevice.biosGeometry   s    
 }}T]]4455r   c                    di d| j                   d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                   z  }|S )Na  parted.Device instance --
  model: %(model)s  path: %(path)s  type: %(type)s
  sectorSize: %(sectorSize)s  physicalSectorSize:  %(physSectorSize)s
  length: %(length)s  openCount: %(openCount)s  readOnly: %(readOnly)s
  externalMode: %(external)s  dirty: %(dirty)s  bootDirty: %(bootDirty)s
  host: %(host)s  did: %(did)s  busy: %(busy)s
  hardwareGeometry: %(hardwareGeom)s  biosGeometry: %(biosGeom)s
  PedDevice: %(ped)rr   r   r   r-   physSectorSizer   r4   r8   externalr=   r@   rB   rD   rG   hardwareGeombiosGeomped)r   r   r   r-   r0   r   r4   r8   r;   r=   r@   rB   rD   rG   rL   rO   r	   )r   ss     r   __str__zDevice.__str__   s"   $$gtzz $6499 $fdii $DOO$-=t?V?V$$%0$..$BLdmm$ $++$ .5djj$ CNt~~$ dii	$ "'	$ 39$))	$
 d33$
 6@ARAR$ T]]$$ r   c                 6    | j                   j                         S )z9Remove all identifying signatures of the partition table.)r	   clobberr'   s    r   rY   zDevice.clobber   rH   r   c                 6    | j                   j                         S )z%Open this Device for read operations.)r	   openr'   s    r   r[   zDevice.open   s     }}!!##r   c                 6    | j                   j                         S )z3Close this Device.  Used after open() method calls.)r	   closer'   s    r   r]   zDevice.close   s     }}""$$r   c                 6    | j                   j                         S )z0Destroy this Device.  Operating system specific.)r	   destroyr'   s    r   r_   zDevice.destroy   s     }}$$&&r   c                 6    | j                   j                         S )z<Remove this Device from the internal libparted device cache.)r	   cache_remover'   s    r   removeFromCachezDevice.removeFromCache   s     }}))++r   c                 6    | j                   j                         S )zSet up the Device for use by an external program.  Call this method
           before running an external program that uses the Device.)r	   begin_external_accessr'   s    r   beginExternalAccesszDevice.beginExternalAccess   s    
 }}2244r   c                 6    | j                   j                         S )zTurn off external access mode for the Device.  Call this method once
           your external program has finished using the Device.)r	   end_external_accessr'   s    r   endExternalAccesszDevice.endExternalAccess   s    
 }}0022r   c                 :    | j                   j                  ||      S )z_From the sector indentified by start, read and return count sectors
           from the Device.)r	   readr   startcounts      r   rj   zDevice.read   s    
 }}!!%//r   c                 <    | j                   j                  |||      S )z^From the sector identified by start, write count sectors from
           buffer to the Device.)r	   write)r   bufrl   rm   s       r   ro   zDevice.write   s    
 }}""3u55r   c                 n    |r| j                   j                         S | j                   j                         S )zPerform a operating-system specific sync(2) operation on the
           Device.  If fast is True, try to perform a fast sync(2).)r	   	sync_fastsync)r   fasts     r   rs   zDevice.sync   s-    
 ==**,,==%%''r   c                 :    | j                   j                  ||      S )zlFrom the sector identified by start, perform an operating
           system specific check on count sectors.)r	   checkrk   s      r   rv   zDevice.check   s     }}""5%00r   c                     | j                   \  }}}t        t        j                  t	        |      ||z  z  dz               S )zMReturn the closest cylinder (round down) to sector on
           this Device.   )rO   longmathfloorr   r   sector_r"   r#   s        r   startSectorToCylinderzDevice.startSectorToCylinder  s<     #//E7DJJ57? CqHIJJr   c                     | j                   \  }}}t        t        j                  t	        |dz         ||z  z              S )zKReturn the closest cylinder (round up) to sector on
           this Device.rx   )rO   ry   rz   ceilr   r|   s        r   endSectorToCylinderzDevice.endSectorToCylinder  s<     #//E7DIIgvz3uwGHIIr   c                 J    | j                   \  }}}t        |dz
  ||z  z        S )z]Return the sector corresponding to cylinder as a
           starting cylinder on this Device.rx   rO   ry   r   cylinderr~   r"   r#   s        r   startCylinderToSectorzDevice.startCylinderToSector  s.     #//E7X\ego677r   c                 J    | j                   \  }}}t        |||z  z  dz
        S )z\Return the sector corresponding to cylinder as an
           ending cylinder on this Device.rx   r   r   s        r   endCylinderToSectorzDevice.endCylinderToSector  s/     #//E7h57?3q899r   c                    t        j                  dt               |j                         }|t        j
                  j                         vrt        d|z        t        | j                  j                        }|t        t        j                  dt        j
                  |               z  }|t        | j                        z  }t        |      S )aU  Return the size of the Device in the unit specified.  The unit
           is given as a string corresponding to one of the following
           abbreviations:  b (bytes), KB (kilobytes), MB (megabytes), GB
           (gigabytes), TB (terabytes).  An invalid unit string will raise a
           SyntaxError exception.  The default unit is MB.zuse the getLength methodzinvalid unit %s giveng      @)warningswarnDeprecationWarninglowerr   	_exponentkeysSyntaxErrorr   r	   r   rz   powr-   float)r   unitlunitsizes       r   getSizezDevice.getSize   s     	02DE

((--//5>??t}}++,)9)9%)@ABB((T{r   c                     | j                   j                  }|dk(  r|S t        j                  || j                  z  |      S )zReturn the length of the device in sectors. Optionally, a SI or
           IEC prefix followed by a 'B' may be given in order to convert the
           length into bytes. The allowed values include B, kB, MB, GB, TB, KiB,
           MiB, GiB, and TiB.r#   )r	   r   r   formatBytesr-   )r   r   r#   s      r   	getLengthzDevice.getLength2  s<     --&&9N!!'DOO";TBBr   c                 ^    t        j                  | j                  j                               S )zOReturn a Constraint defining the limitations imposed by
           this Device.PedConstraint)r   
Constraintr	   get_constraintr'   s    r   getConstraintzDevice.getConstraint=  s"       t}}/K/K/MNNr   c                 b    | j                   j                         }t        j                  |      S )zoReturn a Constraint defining the limitations and minimal advisable
           alignment imposed by this Device.r   )r	   get_minimal_aligned_constraintr   r   r   
constraints     r   minimalAlignedConstraintzDevice.minimalAlignedConstraintC  '    
 ]]AAC
  z::r   c                 b    | j                   j                         }t        j                  |      S )zeReturn a Constraint defining the limitations and optimal
           alignment imposed by this Device.r   )r	   get_optimal_aligned_constraintr   r   r   s     r   optimalAlignedConstraintzDevice.optimalAlignedConstraintK  r   r   c                 b    | j                   j                         }t        j                  |      S )zCReturn an Alignment defining the minimum alignment for this Device.PedAlignment)r	   get_minimum_alignmentr   	Alignmentr   	alignments     r   minimumAlignmentzDevice.minimumAlignmentS  '     MM779	Y77r   c                 b    | j                   j                         }t        j                  |      S )zCReturn an Alignment defining the optimum alignment for this Device.r   )r	   get_optimum_alignmentr   r   r   s     r   optimumAlignmentzDevice.optimumAlignmentZ  r   r   c                     | j                   S )z`Return the _ped.Device object contained in this Device.
           For internal module use only.)r	   r'   s    r   getPedDevicezDevice.getPedDevicea  s     }}r   )NN)F)MB)r#   )2__name__
__module____qualname____doc__r   r   r   r   rJ   propertyr   r   r   r-   r0   r   r4   r8   r;   r=   r@   rB   rD   rG   rL   rO   rW   rY   r[   r]   r_   rb   re   rh   rj   ro   rs   rv   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r   r   &   sJ   Q K K&~F # # " " " " ) ) . . $ $ ( ( - - 1 1 ) ) . . " " ! ! ' ' 4 4 6 6$ ' ' $ $
 % %
 ' '
 , ,
 5 5 3 3 0 0 6 6 ( ( 1 1
 K K J J 8 8 : :$ C C O O
 ;  ; ;  ; 8  8
 8  8
r   r   )sysversion_infointry   rz   decimalr   r   r   r
   parted.decoratorsr   objectr   r   r   r   <module>r      s=   2 uD      %~V ~r   