From d4d54523a8b28f3bc0d2c167829024c1afd411bd Mon Sep 17 00:00:00 2001 From: Esko Kokkonen Date: Wed, 24 Aug 2011 13:18:08 +0300 Subject: [PATCH] rewriting added first class structure --- emerge-timer.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/emerge-timer.py b/emerge-timer.py index a9d8233..4785767 100755 --- a/emerge-timer.py +++ b/emerge-timer.py @@ -1,7 +1,7 @@ #!/usr/bin/python -import sys, subprocess, datetime, os +import sys, subprocess, datetime, os, re PORTDIR = "/usr/portage/" @@ -13,6 +13,50 @@ color_stop = "\033[m" packages = [] +class package: + def __init__(self): + self.name = "" + self.version = "" + self.emerge_time = "" + self.emerge_date = "" + + + def printable_time(self): + time = self.emerge_time + + 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)) + + pdays, phours, pminutes, pseconds = str() + + if days > 0: + pdays = (green_start + str(days) + color_stop + " day") + if days != 1: + pdays += "s" + + if hours > 0: + phours = (green_start + str(hours) + color_stop + " hour") + if hours != 1: + phours += "s" + + if minutes > 0: + pminutes = (green_start + str(minutes) + color_stop + " minute") + if minutes != 1: + pminutes += "s" + + pseconds = green_start + str(seconds) + color_stop + " second") + if seconds != 1: + pseconds += "s" + + return (pdays + phours + pminutes + pdays) + def open_log(): """Attempt to open the LOGFILE.""" @@ -54,7 +98,7 @@ def main(status, package=None): if status == "package": search_log_for_package(package) print packages - pass + elif status == "current": pass -- 2.44.0