Current File : //usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyo
�
.�t_c@s<dZddlZddlmZdefd��YZdS(sw
  SizeString - LVM-style size strings

  $Id: //eng/vdo-releases/magnesium/src/python/vdo/vdomgmnt/SizeString.py#1 $

i����Ni(t	Constantst
SizeStringcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zed��ZRS(s�Represents the size of an object such as a disk partition.

  Conversions are provided to and from suffixed size strings as used
  by LVM commands like lvcreate(8). These strings consist of a
  (possibly floating-point) number followed by an optional unit
  suffix: B (bytes), S (512-byte sectors), and KMGTPE for kilobytes
  through exabytes, respectively. Suffixes are not case-sensitive; the
  default unit is Megabytes. Currently, we reject negative sizes.

  Unlike some (but not all) LVM commands we do not interpret the upper-case
  version of a suffix as a power of ten.

  Attributes:
    _originalString (str): the original string we were constructed
      with, mainly used for debugging
    _bytes (int): the value of this object in bytes

  cCs&td�}|jt|�|_|S(Nt(Rt_bytestint(tselftrhstretval((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__add__4scCs
|jdkS(Ni(R(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__bool__:scCs:d}t|t�st}nt|j|j��}|S(Ni(t
isinstanceRtNotImplementedtcmpRttoBytes(RRtresult((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__cmp__>s
	cCs|jt|�7_|S(N(RR(RR((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__iadd__GscCs|jS(N(R(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__int__LscCs
|j�S(N(R	(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__nonzero__PscCs�tj}|j}|dkr|x[tjddd�D]7}tj|}||dkr5||}|}Pq5q5Wtj}nt|�|j�S(s=Returns this object as a size string without a decimal point.iNi����(RtlvmDefaultSuffixRt
lvmSiSuffixestlvmSiSuffixSizeMapt
lvmByteSuffixtstrtupper(Rtsuffixtsizetclicktdivisor((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt	asLvmTextTs		

cCs|j�tj|_|S(s8Rounds this object down to a multiple of the block size.(ttoBlocksRtVDO_BLOCK_SIZER(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pytroundToBlockescCs|jtjS(s;Returns this object as a count of 4K blocks, rounding down.(RRR(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyRkscCs|jS(s6Returns the count of bytes represented by this object.(R(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyR
pscCs#tjtj}|j|d|S(s@Returns this object as a count of 512-byte sectors, rounding up.i(RtlvmSuffixSizeMaptlvmSectorSuffixR(RtbytesPerSector((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt	toSectorsuscCs�||_|r�yQ|dj�}|tjkrG|j|d �}n|j|�}tj}Wn/tk
r�ttd�jd|���nX|t	tj
|�9}t|�|_|jdkr�ttd�jd|���q�n	d|_dS(Ni����sinvalid size string "{size}"Ri(
t_originalStringtlowerRtlvmSuffixest_atofRt
ValueErrort_tformattfloatR!RR(RtszRtnbytes((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__init__}s	

"$cCs"dj|j|jtjj��S(Ns{0} ({1}{2})(R+R%RRRR(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__repr__�scCs
|j�S(N(R(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__str__�scCs0ytj|�SWntk
r+t|�SXdS(spTries to convert a float using the current LC_NUMERIC settings.
    If something goes wrong, tries float().
    N(tlocaletatoft	ExceptionR,(ts((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyR(�s
(t__name__t
__module__t__doc__RR	RRRRRR RR
R$R/R0R1tstaticmethodR((((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyRs 															(R8R2RRtobjectR(((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt<module>s