]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/webapp/helpers.py
7 suffixes
= ["B", "K", "M", "G", "T",]
10 while s
>= 1024 and idx
< len(suffixes
):
14 return "%.0f%s" % (s
, suffixes
[idx
])
16 def ping(host
, count
=5, wait
=10):
17 cmd
= subprocess
.Popen(
18 ["ping", "-c%d" % count
, "-w%d" % wait
, host
],
19 stdout
= subprocess
.PIPE
,
20 stderr
= subprocess
.PIPE
,
25 out
, error
= cmd
.communicate()
27 for line
in out
.split("\n"):
28 if not line
.startswith("rtt"):
35 rtts
= line
[3].split("/")
39 latency
= "%.1f" % float(rtts
[1])