tools (common/utils): new methods to parse and generate file size with symbols:
- `parseSize` lets parse a size which can be either a int, or a string with a symbol like `Mio` - `getSizeMultiplier` returns a tuple of size with it's multiplier symbol - `getHumanSize` returns a string with size and adapted multiplier.
This commit is contained in:
parent
06054ceeaf
commit
4e36667134
1 changed files with 88 additions and 12 deletions
|
|
@ -30,6 +30,7 @@ from sat_frontends.jp.constants import Const as C
|
|||
from sat_frontends.jp import common
|
||||
from sat_frontends.tools import jid
|
||||
from sat.tools.common.ansi import ANSI as A
|
||||
from sat.tools.common import utils
|
||||
from urllib.parse import urlparse
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
|
|
@ -864,15 +865,7 @@ class ShareList(base.CommandBase):
|
|||
def _size_filter(self, size, row):
|
||||
if not size:
|
||||
return ""
|
||||
size = int(size)
|
||||
# cf. https://stackoverflow.com/a/1094933 (thanks)
|
||||
suffix = "o"
|
||||
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
|
||||
if abs(size) < 1024.0:
|
||||
return A.color(A.BOLD, "{:.2f}".format(size), unit, suffix)
|
||||
size /= 1024.0
|
||||
|
||||
return A.color(A.BOLD, "{:.2f}".format(size), "Yi", suffix)
|
||||
return A.color(A.BOLD, utils.getHumanSize(size))
|
||||
|
||||
def default_output(self, files_data):
|
||||
"""display files a way similar to ls"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue