Skip to content

Commit 3b4121e

Browse files
committed
Have an example program too.
Signed-off-by: Flynn <[email protected]>
1 parent 6a5e7e9 commit 3b4121e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/gep2257.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/python3
2+
# -*- coding:utf-8 -*-
3+
4+
"""
5+
This example uses kubernetes.utils.duration to parse and display
6+
a GEP-2257 duration string (you can find the full specification at
7+
https://gateway-api.sigs.k8s.io/geps/gep-2257/).
8+
9+
Good things to try:
10+
>>> python examples/gep2257.py 1h
11+
Duration: 1h
12+
>>> python examples/gep2257.py 3600s
13+
Duration: 1h
14+
>>> python examples/gep2257.py 90m
15+
Duration: 1h30m
16+
>>> python examples/gep2257.py 30m1h10s5s
17+
Duration: 1h30m15s
18+
>>> python examples/gep2257.py 0h0m0s0ms
19+
Duration: 0s
20+
>>> python examples/gep2257.py -5m
21+
ValueError: Invalid duration format: -5m
22+
>>> python examples/gep2257.py 1.5h
23+
ValueError: Invalid duration format: 1.5h
24+
"""
25+
26+
import sys
27+
28+
from kubernetes.utils import duration
29+
30+
def main():
31+
if len(sys.argv) != 2:
32+
print("Usage: {} <duration>".format(sys.argv[0]))
33+
sys.exit(1)
34+
35+
dur = duration.parse_duration(sys.argv[1])
36+
print("Duration: %s" % duration.format_duration(dur))
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)