Re: [PATCH v2 1/2] git-p4: print size values in appropriate units
- From
Joachim Kuebart <joachim.kuebart@gmail.com>
- Date
- Dec 18, 2021, 07:44 UTC
- Message-ID
- <39F3A9A9-AE61-4C2E-AA66-6B072634D91E@gmail.com>
- In-Reply-To
- <20211217203856.2339161-2-jholdsworth@nvidia.com>
Show 22 quoted lines
> On 17 Dec 2021, at 21:38, Joel Holdsworth <jholdsworth@nvidia.com> wrote:
>
> git-p4.py | 22 +++++++++++++++++-----
> 1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 2b4500226a..4d8a249b85 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -56,6 +56,16 @@
>
> p4_access_checked = False
>
> +def format_size_human_readable(num):
> + """ Returns a number of units (typically bytes) formatted as a human-readable
> + string.
> + """
> + for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
> + if abs(num) < 1024.0:
> + return "{:3.1f} {}B".format(num, unit)
> + num /= 1024.0
> + return "{:.1f} Yi{}B".format(num)This now has an extra pair of braces.
Cheers, Joachim