diff options
author | John Estabrook <jestabro@vyos.io> | 2022-12-12 10:32:43 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-12 10:32:43 -0600 |
commit | 0c5416e9e629a6f9028c85fe5313f43d3484860a (patch) | |
tree | aff6d298dc8c99058b10dcbca8d6b5e7a637b883 /python/vyos | |
parent | 4df8182dfb2e5988d333db1052bb4379b8326527 (diff) | |
parent | 6fb7c09670a80af2f839ccfd4bb94c8b0f745b95 (diff) | |
download | vyos-1x-0c5416e9e629a6f9028c85fe5313f43d3484860a.tar.gz vyos-1x-0c5416e9e629a6f9028c85fe5313f43d3484860a.zip |
Merge pull request #1699 from jestabro/op-mode-openvpn
openvpn: T4770: rewrite op-mode show/reset to use vyos.opmode
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/opmode.py | 6 | ||||
-rw-r--r-- | python/vyos/util.py | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/python/vyos/opmode.py b/python/vyos/opmode.py index 9dba8d30f..5ff768859 100644 --- a/python/vyos/opmode.py +++ b/python/vyos/opmode.py @@ -51,6 +51,12 @@ class IncorrectValue(Error): """ pass +class CommitInProgress(Error): + """ Requested operation is valid, but not possible at the time due + to a commit being in progress. + """ + pass + class InternalError(Error): """ Any situation when VyOS detects that it could not perform an operation correctly due to logic errors in its own code diff --git a/python/vyos/util.py b/python/vyos/util.py index 9ebe69b6c..6a828c0ac 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -539,13 +539,16 @@ def seconds_to_human(s, separator=""): return result -def bytes_to_human(bytes, initial_exponent=0): +def bytes_to_human(bytes, initial_exponent=0, precision=2): """ Converts a value in bytes to a human-readable size string like 640 KB The initial_exponent parameter is the exponent of 2, e.g. 10 (1024) for kilobytes, 20 (1024 * 1024) for megabytes. """ + if bytes == 0: + return "0 B" + from math import log2 bytes = bytes * (2**initial_exponent) @@ -571,7 +574,7 @@ def bytes_to_human(bytes, initial_exponent=0): # Add a new case when the first machine with petabyte RAM # hits the market. - size_string = "{0:.2f} {1}".format(value, suffix) + size_string = "{0:.{1}f} {2}".format(value, precision, suffix) return size_string def human_to_bytes(value): |