Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/vdo/vdomgmnt/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/vdo/vdomgmnt/__pycache__/SizeString.cpython-36.pyc

3

x?ag_�@s\dZddlmZddlmZddlmZddlmZddlZddlmZGd	d
�d
e	�Z
dS)zv
  SizeString - LVM-style size strings

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

�)�absolute_import)�division)�print_function)�unicode_literalsN�)�	Constantsc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zed(d)��Zd*S)+�
SizeStringa�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

  cCstd�}|jt|�|_|S)N�)r�_bytes�int)�self�rhsZretval�r� /usr/lib/python3.6/SizeString.py�__add__8szSizeString.__add__cCs
|jdkS)Nr)r
)rrrr�__bool__>szSizeString.__bool__cCs"t|t�st}n|j|j�k}|S)N)�
isinstancer�NotImplementedr
�toBytes)rr
�resultrrr�__eq__Bs
zSizeString.__eq__cCs"t|t�st}n|j|j�k}|S)N)rrrr
r)rr
rrrr�__ne__Js
zSizeString.__ne__cCs"t|t�st}n|j|j�k}|S)N)rrrr
r)rr
rrrr�__lt__Rs
zSizeString.__lt__cCs"t|t�st}n|j|j�k}|S)N)rrrr
r)rr
rrrr�__le__Zs
zSizeString.__le__cCs"t|t�st}n|j|j�k}|S)N)rrrr
r)rr
rrrr�__gt__bs
zSizeString.__gt__cCs"t|t�st}n|j|j�k}|S)N)rrrr
r)rr
rrrr�__ge__js
zSizeString.__ge__cCs|jt|�7_|S)N)r
r)rr
rrr�__iadd__rszSizeString.__iadd__cCs|jS)N)r
)rrrr�__int__wszSizeString.__int__cCs|j�S)N)r)rrrr�__nonzero__{szSizeString.__nonzero__cCshtj}|j}|dkrXxBtjddd�D](}tj|}||dkr&||}|}Pq&Wtj}t|�|j�S)z=Returns this object as a size string without a decimal point.rNr���)r�lvmDefaultSuffixr
Z
lvmSiSuffixesZlvmSiSuffixSizeMap�
lvmByteSuffix�str�upper)r�suffix�sizeZclickZdivisorrrr�	asLvmTexts
zSizeString.asLvmTextcCs|j�tj|_|S)z8Rounds this object down to a multiple of the block size.)�toBlocksr�VDO_BLOCK_SIZEr
)rrrr�roundToBlock�szSizeString.roundToBlockcCs|jtjS)z;Returns this object as a count of 4K blocks, rounding down.)r
rr()rrrrr'�szSizeString.toBlockscCs|jS)z6Returns the count of bytes represented by this object.)r
)rrrrr�szSizeString.toBytescCstjtj}|j|d|S)z@Returns this object as a count of 512-byte sectors, rounding up.r)r�lvmSuffixSizeMapZlvmSectorSuffixr
)rZbytesPerSectorrrr�	toSectors�szSizeString.toSectorscCs�||_|r�yB|dd�j�}|tjkr:|j|dd��}n|j|�}tj}Wn(tk
rtttd�j|d���YnX|t	tj
|�9}t|�|_|jdkr�ttd�j|d���nd|_dS)Nrzinvalid size string "{size}")r%rrr)
�_originalString�lowerrZlvmSuffixes�_atofr �
ValueError�_�format�floatr*rr
)rZszr$�nbytesrrr�__init__�s




zSizeString.__init__cCsdj|j|jtjj��S)Nz{0} ({1}{2}))r1r,r
rr!r#)rrrr�__repr__�szSizeString.__repr__cCs|j�S)N)r&)rrrr�__str__�szSizeString.__str__cCs(y
tj|�Stk
r"t|�SXdS)zpTries to convert a float using the current LC_NUMERIC settings.
    If something goes wrong, tries float().
    N)�localeZatof�	Exceptionr2)�srrrr.�s
zSizeString._atofN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrrr&r)r'rr+r4r5r6�staticmethodr.rrrrr!s*r)r=Z
__future__rrrrr7r	r�objectrrrrr�<module>s

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists