summaryrefslogtreecommitdiff
path: root/swiftclient/utils.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2023-03-20 11:27:50 -0700
committerTim Burke <tim.burke@gmail.com>2023-03-20 17:23:38 -0700
commit9e703b9345cffd90d723e0ce5c180a385c75c62e (patch)
tree47706cf818b87f90126015cb03425c7a8ced1d02 /swiftclient/utils.py
parent779cf7484e44855ddbf6f29d48af79104e42a0a6 (diff)
downloadpython-swiftclient-9e703b9345cffd90d723e0ce5c180a385c75c62e.tar.gz
shell: Allow timeouts to have units
Related-Change: Ibbe7e5aa8aa8e54935da76109c2ea13fb83bc7ab Change-Id: Ifeaaea790d1dadc84b157a7cf2be7590949c70f0
Diffstat (limited to 'swiftclient/utils.py')
-rw-r--r--swiftclient/utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/swiftclient/utils.py b/swiftclient/utils.py
index 0a67537..39481e4 100644
--- a/swiftclient/utils.py
+++ b/swiftclient/utils.py
@@ -70,6 +70,20 @@ def prt_bytes(num_bytes, human_flag):
return '%.1f%s' % (num, suffix)
+def parse_timeout(value):
+ for suffix, multiplier in (
+ ('s', 1),
+ ('m', 60),
+ ('min', 60),
+ ('h', 60 * 60),
+ ('hr', 60 * 60),
+ ('d', 24 * 60 * 60),
+ ):
+ if value.endswith(suffix):
+ return multiplier * float(value[:-len(suffix)])
+ return float(value)
+
+
def parse_timestamp(seconds, absolute=False):
try:
try: