]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Improve current process handling
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Mon, 29 Aug 2011 15:05:21 +0000 (18:05 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Mon, 29 Aug 2011 15:05:21 +0000 (18:05 +0300)
Use the same method of getting the package name as in the pretended
function. Now the print_current_emerges function is simplified by not
having to go through the list of all the package names.

emerge-timer.py

index c2ef4447621d928894cdec09e66cc882c1611aab..81810ce74b9c1cc5f0e004385fb150a101d3175a 100755 (executable)
@@ -250,21 +250,28 @@ def list_emerge_processes(f):
         if (("ebuild.sh" in i) and ("/bin/bash" not in i)):
              pack = i.partition('[')[2].partition(']')[0]
 
-             packages.append([pack, 12*3600])
+             version = pack.partition('/')[2].partition('-')[2]
+
+             while not version[0].isdigit():
+                 version = version.partition('-')[2]
+
+             package_name = pack[:-len(version)-1]
+
+             packages.append([package_name, '-'+version, 12*3600])
 
 
     for line in f:
         if ((">>>" in line) and ("emerge" in line)):
             for p in packages:
-                if (p[0] in line):
+                if (p[0]+p[1] in line):
 
                     time = float(line.partition(' ')[0].strip(":"))
 
                     timestamp = datetime.datetime.fromtimestamp(time)
                     difference = (now - timestamp).total_seconds()
 
-                    if difference < p[1]:
-                        p[1] = difference
+                    if difference < p[2]:
+                        p[2] = difference
 
 
     if len(packages) == 0:
@@ -280,28 +287,27 @@ def print_current_emerges(f, packages):
     """Print the current packages that are being merged with the
     current emerge time."""
 
-    all_packages = list_all_packages()
 
     print("Currently emerging: ")
 
     for p in packages:
-        print("\t" + green_start + p[0] + color_stop),
+        print("\t" + green_start + p[0] + p[1] + color_stop),
         print("\n\t  current emerge time:\t"),
 
-        organize_times(p[1])
+        organize_times(p[2])
         print
 
-
-        for i in all_packages:
-            if i in p[0]:
-                average_time = main_loop(f, i, True)
+        average_time = main_loop(f, p[0], True)
 
         if average_time != 0:
             print("\n\t  " + '-'*45 + "\n\t  time to finish: \t"),
-            if (average_time - p[1]) < 0:
+
+            if (average_time - p[2]) < 0:
                 print(green_start + "Any time now" + color_stop),
+
             else:
-                organize_times(average_time - p[1])
+                organize_times(average_time - p[2])
+
             print "\n"