]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Make a new function that has all the current emerge printing stuff
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Sun, 14 Aug 2011 16:10:18 +0000 (19:10 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Sun, 14 Aug 2011 16:10:18 +0000 (19:10 +0300)
Keep the calculation stuff in the list_emerge_processes function but
make a new function with all the printing it used to do. Also the
packages list now is in the form [package, emerge-time]. Pass this
list to the printing function so it can print the emerge time aswell.

emerge-timer.py

index ec2075a74706d02bb632a979d0a74953dc3fbc89..2c983f9d75ec00a941a4305620197541c66b838b 100755 (executable)
@@ -231,13 +231,14 @@ def list_emerge_processes(f):
     the command for the package. With this package search the LOGFILE for
     the emerge startup time."""
 
-
+    now = datetime.datetime.today()
     packages = []
+
     for i in os.popen("ps ax"):
         if (("ebuild" in i) and ("/bin/bash" not in i)):
              pack = i.partition('[')[2].partition(']')[0]
 
-             packages.append([pack, 0])
+             packages.append([pack, 12*3600])
 
 
     for line in f:
@@ -246,38 +247,40 @@ def list_emerge_processes(f):
                 if (p[0] in line):
 
                     time = float(line.partition(' ')[0].strip(":"))
-                    if time > p[1]:
-                        p[1] = time
+
+                    timestamp = datetime.datetime.fromtimestamp(time)
+                    difference = (now - timestamp).total_seconds()
+
+                    if difference < p[1]:
+                        p[1] = difference
 
 
     if len(packages) == 0:
         print "No current emerge process found."
         return
 
+    print_current_emerges(f, packages)
+
 
-    # Here we go through all the packages we have found and
-    # printout the current emerge time
-    a = 1
-    for p in packages:
-        now = datetime.datetime.today()
-        timestamp = datetime.datetime.fromtimestamp(p[1])
 
-        difference = now - timestamp
 
+def print_current_emerges(f, packages):
+    """Print the current packages that are being merged with the
+    current emerge time."""
 
-        if a:
-            print("Currently emerging: ")
-            a = 0
+    print("Currently emerging: ")
 
+    for p in packages:
         print("\t" + green_start + p[0] + color_stop),
         print('\n\t  current emerge time: '),
 
-        organize_times(difference.total_seconds())
+        organize_times(p[1])
         print
 
 
         name = (p[0].partition('-')[0] + '-' +
                 p[0].partition('-')[2].partition('-')[0])
+
         main_loop(f, name, True)