From: Esko Kokkonen Date: Sun, 18 Sep 2011 15:03:04 +0000 (+0300) Subject: Drop time() and date() from the class X-Git-Url: http://git.itanic.dy.fi/?p=emerge-timer;a=commitdiff_plain;h=0979be8eca85b8bed583ac66297403856d2cdc5d Drop time() and date() from the class These don't need to be inside the class as they don't contribute to the class variables in any way. --- diff --git a/emerge-timer.py b/emerge-timer.py index f911fc4..ede2950 100755 --- a/emerge-timer.py +++ b/emerge-timer.py @@ -67,11 +67,11 @@ class package: """Function used to print all the current emerge stuff""" print("\t" + green_start + self.name + '-' + self.version + - color_stop + "\n\t current time: " + self.time(self.emerge_time) + + color_stop + "\n\t current time: " + time(self.emerge_time) + "\n\t average time: "), if len(self.versions) > 1: - print(self.time(self.average_time())), + print(time(self.average_time())), else: print("unknown"), @@ -82,7 +82,7 @@ class package: print("\n\t time to finish: "), if finish_time > 0: - print(self.time(finish_time)) + print(time(finish_time)) else: print("any time now") @@ -95,8 +95,7 @@ class package: print('-'*90 + "\n" + green_start + self.name + p[0] + color_stop + " >>> " + - self.time(p[1]) + " >>> " + - self.date(p[2])) + time(p[1]) + " >>> " + date(p[2])) print('-'*90 + "\n" + "Package " + green_start + self.name + color_stop + " emerged " + @@ -110,7 +109,7 @@ class package: print("\t" + green_start + self.name + '-' + self.version + color_stop), if len(self.versions) > 1: - print("\n\taverage time: " + self.time(self.average_time())) + print("\n\taverage time: " + time(self.average_time())) else: print("\n\t no previous emerges") @@ -121,67 +120,67 @@ class package: average = self.average_time() total = self.total_time() - print("Max time: \t" + self.time(maxi) + - "\nMin time: \t" + self.time(mini) + - "\nAverage time: \t" + self.time(average) + - "\nIn total spent " + self.time(total) + + print("Max time: \t" + time(maxi) + + "\nMin time: \t" + time(mini) + + "\nAverage time: \t" + time(average) + + "\nIn total spent " + time(total) + " emerging " + green_start + self.name + color_stop) - def time(self, time): - """Converts time in seconds to human readable form""" - days = time/(3600*24) - hours = (days - int(days))*24 - minutes = (hours - int(hours))*60 - seconds = (minutes - int(minutes))*60 +def time(time): + """Converts time in seconds to human readable form""" + days = time/(3600*24) + hours = (days - int(days))*24 + minutes = (hours - int(hours))*60 + seconds = (minutes - int(minutes))*60 - days = int(days) - hours = int(hours) - minutes = int(minutes) - seconds = int(round(seconds)) + days = int(days) + hours = int(hours) + minutes = int(minutes) + seconds = int(round(seconds)) - pdays = str() - phours = str() - pminutes = str() - pseconds = str() + pdays = str() + phours = str() + pminutes = str() + pseconds = str() - if days > 0: + if days > 0: + pdays = (green_start + str(days) + + color_stop + " day ") + if days != 1: pdays = (green_start + str(days) + - color_stop + " day ") - if days != 1: - pdays = (green_start + str(days) + color_stop + " days ") - if hours > 0: + if hours > 0: + phours = (green_start + str(hours) + + color_stop + " hour ") + if hours != 1: phours = (green_start + str(hours) + - color_stop + " hour ") - if hours != 1: - phours = (green_start + str(hours) + color_stop + " hours ") - if minutes > 0: + if minutes > 0: + pminutes = (green_start + str(minutes) + + color_stop + " minute ") + if minutes != 1: pminutes = (green_start + str(minutes) + - color_stop + " minute ") - if minutes != 1: - pminutes = (green_start + str(minutes) + - color_stop + " minutes ") + color_stop + " minutes ") + pseconds = (green_start + str(seconds) + + color_stop + " second ") + if seconds != 1: pseconds = (green_start + str(seconds) + - color_stop + " second ") - if seconds != 1: - pseconds = (green_start + str(seconds) + - color_stop + " seconds ") + color_stop + " seconds ") - return (pdays + phours + pminutes + pseconds) + return (pdays + phours + pminutes + pseconds) - def date(self, emerge_date): - """Returns a date string from a standard POSIX time""" - date = datetime.datetime.fromtimestamp(emerge_date) +def date(emerge_date): + """Returns a date string from a standard POSIX time""" + date = datetime.datetime.fromtimestamp(emerge_date) - date = "{:%d.%m.%Y %H:%M:%S}".format(date) + date = "{:%d.%m.%Y %H:%M:%S}".format(date) - return date + return date