Skip to content

Commit

Permalink
exact division;
Browse files Browse the repository at this point in the history
for compatibility between py2 and py3
  • Loading branch information
mythmgn committed Oct 27, 2021
1 parent bdf21af commit 1ce067a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ examples/arrow-runtime/data/TOPDIR
examples/arrow-runtime/arrow/master/master.pid
examples/arrow-runtime/arrow/master/master.pid
*.pid
py3.out
18 changes: 9 additions & 9 deletions cup/res/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ def get_disk_usage_all(raw=False):
if not raw:
if total > byte2gb:
free, total = \
free / byte2gb, total / byte2gb
free // byte2gb, total // byte2gb
unit = "GB"
elif total > byte2mb:
free, total = \
free / byte2mb, total / byte2mb
free // byte2mb, total // byte2mb
unit = "MB"
return {
"totalSpace": total,
Expand Down Expand Up @@ -365,7 +365,7 @@ def get_cpu_usage(intvl_in_sec=1):
ret[i] = minus

for i in range(0, len(ret)):
ret[i] = ret[i] * 100 / total
ret[i] = ret[i] * 100 // total
return CPUInfo(*ret)


Expand All @@ -388,7 +388,7 @@ def get_cpu_core_usage(coreindex, intvl_in_sec=1):
ret[i] = minus

for i in range(0, len(ret)):
ret[i] = ret[i] * 100 / total
ret[i] = ret[i] * 100 // total
return CPUInfo(*ret)


Expand Down Expand Up @@ -428,7 +428,7 @@ def get_meminfo():
fp.close()
avail = free + buffers + cached
used = total - free
percent = int((total - avail) * 100 / total)
percent = int((total - avail) * 100 // total)
return MemInfo(
total,
avail,
Expand Down Expand Up @@ -600,7 +600,7 @@ def get_net_transmit_speed(str_interface, intvl_in_sec=1):
rx_bytes0 = get_net_through(str_interface)[0]
time.sleep(intvl_in_sec)
rx_bytes1 = get_net_through(str_interface)[0]
return (rx_bytes1 - rx_bytes0) / intvl_in_sec
return (rx_bytes1 - rx_bytes0) // intvl_in_sec



Expand All @@ -613,7 +613,7 @@ def get_net_recv_speed(str_interface, intvl_in_sec):
tx_bytes0 = get_net_through(str_interface)[1]
time.sleep(intvl_in_sec)
tx_bytes1 = get_net_through(str_interface)[1]
return (tx_bytes1 - tx_bytes0) / intvl_in_sec
return (tx_bytes1 - tx_bytes0) // intvl_in_sec


def wrap_exceptions(fun):
Expand Down Expand Up @@ -916,8 +916,8 @@ def get_cpu_times(self):
# ignore the first two values ("pid (exe)")
st = st[st.find(')') + 2:]
values = st.split(' ')
utime = float(values[11]) / _CLOCK_TICKS
stime = float(values[12]) / _CLOCK_TICKS
utime = float(values[11]) // _CLOCK_TICKS
stime = float(values[12]) // _CLOCK_TICKS
return self._nt_cputimes(utime, stime)

@wrap_exceptions
Expand Down
10 changes: 5 additions & 5 deletions cup/res/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ def _get_disk_usage_all(raw=False):
if not raw:
if total > byte2gb:
free, total = \
free / byte2gb, total / byte2gb
free // byte2gb, total // byte2gb
unit = "GB"
elif total > byte2mb:
free, total = \
free / byte2mb, total / byte2mb
free // byte2mb, total // byte2mb
unit = "MB"
return {
"totalSpace": total,
Expand Down Expand Up @@ -179,7 +179,7 @@ def get_cpu_usage(intvl_in_sec=1):
ret[i] = minus

for i in range(0, len(ret)):
ret[i] = ret[i] * 100 / total
ret[i] = ret[i] * 100 // total
return CPUInfo(*ret)


Expand Down Expand Up @@ -218,7 +218,7 @@ def get_net_transmit_speed(str_interface, intvl_in_sec=1):
rx_bytes0 = get_net_through(str_interface)[0]
time.sleep(intvl_in_sec)
rx_bytes1 = get_net_through(str_interface)[0]
return (rx_bytes1 - rx_bytes0) / intvl_in_sec
return (rx_bytes1 - rx_bytes0) // intvl_in_sec


def get_net_recv_speed(str_interface, intvl_in_sec):
Expand All @@ -230,7 +230,7 @@ def get_net_recv_speed(str_interface, intvl_in_sec):
tx_bytes0 = get_net_through(str_interface)[1]
time.sleep(intvl_in_sec)
tx_bytes1 = get_net_through(str_interface)[1]
return (tx_bytes1 - tx_bytes0) / intvl_in_sec
return (tx_bytes1 - tx_bytes0) // intvl_in_sec


if '__main__' == __name__:
Expand Down

0 comments on commit 1ce067a

Please sign in to comment.