Force conversion unit in format_size
Hi,
We are interested in adding an optional flag to format_size() so you can force the conversion unit.
Here is the desired behaviour:
python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4))"
4 GB
python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='bytes'))"
4000000000 bytes
python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='KB'))"
4000000 KB
python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='MB'))"
4000 MB
python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='GB'))"
4 GB
python3 -c "import humanfriendly; print(humanfriendly.format_size(1000 ** 3 * 4, force_unit='TB'))"
0 TB
Best regards, Sebastian
Coverage increased (+0.003%) to 93.417% when pulling 57ba6f73f172ef3087a680c4dea6bf518bdb6053 on sebastian-luna-valero:force-units into 05d02d4f6ef317edf97aca679411ec6514685243 on xolox:master.
Hi @xolox
All tests are passing except for coveralls which I don't know how to fix.
Please have a look and let me know your thoughts.
Many thanks, Sebastian
Hi again,
Alright so adding tests for the new code solves the coveralls issue.
Please have a look and let me know your thoughts.
Best regards, Sebastian
any news on this? its exactly what im looking for
Hi,
Probably my changes are a bit too much for this package and that's why it hasn't been merge.
I have just taken the relevant code out and copied it to my own script. @yodog I recommend you to do the same.
If you think it is interesting, I might upload it to my own git repo and share it with you.
Best regards, Sebastian