my_utilities.view package¶
Submodules¶
my_utilities.view.converter_size_to_pretty_view module¶
Module with function for convert bytes size to correct size in kb/mb/gb
- class my_utilities.view.converter_size_to_pretty_view.SystemTypes(*values)[source]¶
Bases:
StrEnumEnum of available conversion systems
- ALTERNATIVE = 'alternative_name'¶
- IEC = 'iec_name'¶
- SI = 'si_name'¶
- TRADITIONAL = 'traditional_name'¶
- VERBOSE = 'verbose_name'¶
- static _generate_next_value_(name, start, count, last_values)¶
Return the lower-cased version of the member name.
- class my_utilities.view.converter_size_to_pretty_view.SystemValue(**data)[source]¶
Bases:
BaseModelClass for storing information about different weights
- Parameters:
pow (int)
traditional_name (str)
alternative_name (str | tuple[str, str])
verbose_name (tuple[str, str])
iec_name (str)
si_name (str)
value_base (int)
value_si (int)
- _abc_impl = <_abc._abc_data object>¶
- alternative_name: str | tuple[str, str]¶
- get_amount(bytes_value, round_to=2, is_si=False)[source]¶
Method get size of bytes value in system
- Parameters:
bytes_value (int) – bytes to convert
round_to (int) – decimal point rounding precision
is_si (bool) – is to ‘si’ system convert
- Return type:
float- Returns:
- get_normalized_size(bytes_value, system='traditional', round_to=2)[source]¶
Method convert bytes value in chose system :type bytes_value:
int:param bytes_value: bytes value to convert :type bytes_value: int :type system:str|None:param system: system to which to convert :type system: str :type round_to:int|None:param round_to: :type round_to: decimal point rounding precision :return: converted value :rtype: str :raise ValueError: if incorrect system name- Parameters:
bytes_value (int)
system (str | None)
round_to (int | None)
- Return type:
str
- get_size_suffix(system='traditional')[source]¶
method return str title for chose type :type system:
str:param system: title system for viewallowed: [si, iec, verbose, alternative, traditional]
- Returns:
names for chose system
- Return type:
str | tuple[str, str]
- Raises:
ValueError – if there is no selected system
- Parameters:
system (str)
- iec_name: str¶
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- pow: int¶
- si_name: str¶
- traditional_name: str¶
- value_base: int¶
- value_si: int¶
- verbose_name: tuple[str, str]¶
- my_utilities.view.converter_size_to_pretty_view.size(bytes_value, system='traditional', round_to=2)[source]¶
Method for print size of file from bytes to pretty print :type bytes_value:
int:param bytes_value: bytes to convert :type bytes_value: :type system:str|None:param system: :type system: :type round_to:int:param round_to: decimal point rounding precision :type round_to: int :return: converted bytes_value to pretty string :rtype: str :raise ValueError: if incorrect system name or round_to is less 0 :raise TypeError: if incorrect type round_to- Example:
- Parameters:
bytes_value (int)
system (str | None)
round_to (int)
- Return type:
str
Using the traditional system, where a factor of 1024 is used:
>>> size(10)
‘10B’ >>> size(2000) ‘1.95K’ >>> size(20000) ‘19.53K’ >>> size(200000) ‘0.19M’ >>> size(1000000) ‘0.95M’ >>> size(2000000) ‘1.91M’ # use si >>> size(10, system=”si”) ‘10B’ >>> size(2000, system=”si”) ‘2K’ >>> size(20000, system=”si”) ‘20K’ >>> size(200000, system=”si”) ‘0.2M’ >>> size(1000000, system=”si”) ‘1M’ >>> size(2000000, system=”si”) ‘2M’