From 74e8ff73da3efcb4e78358825b0d6b610197f721 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 25 Jul 2016 19:05:26 +0300 Subject: [PATCH] Use integer division for Py3 compatibility --- m_lib/opdate.py | 28 ++++++++++++++-------------- m_lib/opstring.py | 2 +- m_lib/pbar/tty_pbar.py | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/m_lib/opdate.py b/m_lib/opdate.py index 6d23086..e6940a9 100755 --- a/m_lib/opdate.py +++ b/m_lib/opdate.py @@ -110,7 +110,7 @@ def DMYtoDate(Day, Month, Year): Year = Year - 1 Year = Year - MinYear - return (((Year / 100)*146097) / 4) + (((Year % 100)*1461) / 4) + (((153*Month)+2) / 5)+Day+First2Months + return (((Year // 100)*146097) // 4) + (((Year % 100)*1461) // 4) + (((153*Month)+2) // 5)+Day+First2Months def DateToDMY(Julian): @@ -128,11 +128,11 @@ def DateToDMY(Julian): Day = Julian-30 else: I = (4*(Julian-First2Months))-1 - J = (4*((I % 146097) / 4))+3 - Year = (100*(I / 146097))+(J / 1461) - I = (5*(((J % 1461)+4) / 4))-3 - Month = I / 153 - Day = ((I % 153)+5) / 5 + J = (4*((I % 146097) // 4))+3 + Year = (100*(I // 146097))+(J // 1461) + I = (5*(((J % 1461)+4) // 4))-3 + Month = I // 153 + Day = ((I % 153)+5) // 5 if Month < 10: Month = Month + 3 else: @@ -155,7 +155,7 @@ def IncDate(Julian, Days, Months, Years): Day = 28 Year = Year + Years - Year = Year + Months / 12 + Year = Year + Months // 12 Month = Month + Months % 12 if Month < 1: Month = Month + 12 @@ -181,7 +181,7 @@ def IncDateTrunc(Julian, Months, Years): Day = 28 Year = Year + Years - Year = Year + Months / 12 + Year = Year + Months // 12 Month = Month + Months % 12 if Month < 1: Month = Month + 12 @@ -273,9 +273,9 @@ def TimeToHMS(T): return 0, 0, 0 else: - Hours = T / SecondsInHour + Hours = T // SecondsInHour T = T - Hours*SecondsInHour - Minutes = T / SecondsInMinute + Minutes = T // SecondsInMinute T = T - Minutes*SecondsInMinute Seconds = T @@ -334,7 +334,7 @@ def RoundToNearestHour(T, Truncate = False): Seconds = 0 if not Truncate: - if Minutes >= (MinutesInHour / 2): + if Minutes >= (MinutesInHour // 2): Hours = Hours + 1 Minutes = 0 @@ -346,7 +346,7 @@ def RoundToNearestMinute(T, Truncate = False): Hours, Minutes, Seconds = TimeToHMS(T) if not Truncate: - if Seconds >= (SecondsInMinute / 2): + if Seconds >= (SecondsInMinute // 2): Minutes = Minutes + 1 Seconds = 0 @@ -387,7 +387,7 @@ def IncDateTime(DT1, Days, Secs): Secs = -Secs # adjust the date - DT2[0] = DT2[0] - Secs / SecondsInDay + DT2[0] = DT2[0] - Secs // SecondsInDay Secs = Secs % SecondsInDay if Secs > DT2[1]: @@ -403,7 +403,7 @@ def IncDateTime(DT1, Days, Secs): DT2[1] = DT2[1] + Secs # adjust date if necessary - DT2[0] = DT2[0] + DT2[1] / SecondsInDay + DT2[0] = DT2[0] + DT2[1] // SecondsInDay # force time to 0..SecondsInDay-1 range DT2[1] = DT2[1] % SecondsInDay diff --git a/m_lib/opstring.py b/m_lib/opstring.py index 0341bce..cb83a8a 100755 --- a/m_lib/opstring.py +++ b/m_lib/opstring.py @@ -66,7 +66,7 @@ def CenterCh(S, Ch, Width): if len(S) >= Width: return S else: - l = (Width - len(S)) / 2 + l = (Width - len(S)) // 2 r = Width - len(S) - l return Ch*l + S + Ch*r diff --git a/m_lib/pbar/tty_pbar.py b/m_lib/pbar/tty_pbar.py index 8953f6b..0bf4223 100644 --- a/m_lib/pbar/tty_pbar.py +++ b/m_lib/pbar/tty_pbar.py @@ -56,12 +56,12 @@ class ttyProgressBar: self.current = current current -= self.min - lng = (current * self.width1) / self.max + lng = (current * self.width1) // self.max if current >= self.max: percent = 100 else: - percent = (current * 100) / self.max + percent = (current * 100) // self.max flush = False -- 2.39.5