Return a human-readable value for the `size` int or float. For example: >>> assert format_size(0) == '0 Byte' >>> assert format_size(1) == '1 Byte' >>> assert format_size(0.123) == '0.1 Byte' >>> assert format_size(123) == '123 Bytes' >>> assert format_size(1023) == '10
(size)
| 1649 | |
| 1650 | |
| 1651 | def format_size(size): |
| 1652 | """ |
| 1653 | Return a human-readable value for the `size` int or float. |
| 1654 | |
| 1655 | For example: |
| 1656 | >>> assert format_size(0) == '0 Byte' |
| 1657 | >>> assert format_size(1) == '1 Byte' |
| 1658 | >>> assert format_size(0.123) == '0.1 Byte' |
| 1659 | >>> assert format_size(123) == '123 Bytes' |
| 1660 | >>> assert format_size(1023) == '1023 Bytes' |
| 1661 | >>> assert format_size(1024) == '1 KB' |
| 1662 | >>> assert format_size(2567) == '2.51 KB' |
| 1663 | >>> assert format_size(2567000) == '2.45 MB' |
| 1664 | >>> assert format_size(1024*1024) == '1 MB' |
| 1665 | >>> assert format_size(1024*1024*1024) == '1 GB' |
| 1666 | >>> assert format_size(1024*1024*1024*12.3) == '12.30 GB' |
| 1667 | """ |
| 1668 | if not size: |
| 1669 | return '0 Byte' |
| 1670 | if size < 1: |
| 1671 | return '%(size).1f Byte' % locals() |
| 1672 | if size == 1: |
| 1673 | return '%(size)d Byte' % locals() |
| 1674 | size = float(size) |
| 1675 | for symbol in ('Bytes', 'KB', 'MB', 'GB', 'TB'): |
| 1676 | if size < 1024: |
| 1677 | if int(size) == float(size): |
| 1678 | return '%(size)d %(symbol)s' % locals() |
| 1679 | return '%(size).2f %(symbol)s' % locals() |
| 1680 | size = size / 1024. |
| 1681 | return '%(size).2f %(symbol)s' % locals() |
| 1682 | |
| 1683 | |
| 1684 | def get_pretty_params(ctx, generic_paths=False): |
no outgoing calls
no test coverage detected