Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_file.py @ 3524:584379473925
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 05 May 2021 15:37:33 +0200 |
parents | be6d91572633 |
children | 849374e59178 |
comparison
equal
deleted
inserted
replaced
3523:30779935c0aa | 3524:584379473925 |
---|---|
27 from sat.core.log import getLogger | 27 from sat.core.log import getLogger |
28 from sat.core import exceptions | 28 from sat.core import exceptions |
29 from sat.tools import xml_tools | 29 from sat.tools import xml_tools |
30 from sat.tools import stream | 30 from sat.tools import stream |
31 from sat.tools import utils | 31 from sat.tools import utils |
32 from sat.tools.common import utils as common_utils | |
32 | 33 |
33 | 34 |
34 log = getLogger(__name__) | 35 log = getLogger(__name__) |
35 | 36 |
36 | 37 |
319 return ret_value | 320 return ret_value |
320 filename = file_data["name"] | 321 filename = file_data["name"] |
321 assert filename and not "/" in filename | 322 assert filename and not "/" in filename |
322 assert PROGRESS_ID_KEY in file_data | 323 assert PROGRESS_ID_KEY in file_data |
323 # human readable size | 324 # human readable size |
324 file_data["size_human"] = "{:.6n} Mio".format( | 325 file_data["size_human"] = common_utils.getHumanSize(file_data["size"]) |
325 float(file_data["size"]) / (1024 ** 2) | |
326 ) | |
327 d = xml_tools.deferDialog( | 326 d = xml_tools.deferDialog( |
328 self.host, | 327 self.host, |
329 _(CONFIRM).format(peer=peer_jid.full(), **file_data), | 328 _(CONFIRM).format(peer=peer_jid.full(), **file_data), |
330 _(CONFIRM_TITLE), | 329 _(CONFIRM_TITLE), |
331 type_=C.XMLUI_DIALOG_FILE, | 330 type_=C.XMLUI_DIALOG_FILE, |