.t_c@s<dZddlZddlmZdefdYZdS(sw SizeString - LVM-style size strings $Id: //eng/vdo-releases/magnesium/src/python/vdo/vdomgmnt/SizeString.py#1 $ iNi(t Constantst SizeStringcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZedZRS(sRepresents 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|tst}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 |jS(N(R (R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt __nonzero__PscCstj}|j}|dkr|x[tjdddD]7}tj|}||dkr5||}|}Pq5q5Wtj}nt||jS(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|jtj|_|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||_|ryQ|dj}|tjkrG|j|d }n|j|}tj}Wn/tk rttdjd|nX|t tj |9}t ||_ |j dkrttdjd|qn d|_ dS(Nisinvalid size string "{size}"Ri( t_originalStringtlowerRt lvmSuffixest_atofRt ValueErrort_tformattfloatR!RR(RtszRtnbytes((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__init__}s   "$cCs"dj|j|jtjjS(Ns {0} ({1}{2})(R+R%RRRR(R((s;/usr/lib/python2.7/site-packages/vdo/vdomgmnt/SizeString.pyt__repr__s cCs |jS(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.pyts