]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Improve current emerge-time process
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Sat, 13 Aug 2011 13:07:51 +0000 (16:07 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Sat, 13 Aug 2011 13:07:51 +0000 (16:07 +0300)
Instead of tediously scanning the emerge.log, look for the ebuild
process and get the package from there. Then look for the most recent
emerge startup time for that package and calculate the current emerge
time.

emerge-timer.py

index df9a4027f3916dce7afc9056110b2aff2109cb06..7967574b97bf55a4f2a79ad525c12082dcd9399e 100755 (executable)
@@ -182,27 +182,22 @@ def open_log():
         return f
 
 
-def current_emerges(f):
-    packages = []
-    for line in f:
-        if ((">>>" in line) and ("emerge" in line)):
-            part = line.partition(' ')
-
-            time = float(part[0].strip(":"))
+def list_emerge_processes(f):
 
-            # The logfile string is in form of
-            # '1309638757:  >>> emerge (1 of 1) x11-libs/cairo-1.10.2-r1 to /'
-            # so the package is the sixth string pattern when partitioed
-            # with whitespace
-            for i in range(7):
-                part  = part[2].partition(' ')
+    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((part[0], time))
+             packages.append([pack, 0])
 
+    for line in f:
         for p in packages:
-            if ((p[0] in line) and ('completed emerge' in line)):
-                packages.remove(p)
+            if ((p[0] in line) and (">>>" in line) and ("emerge" in line)):
 
+                time = float(line.partition(' ')[0].strip(":"))
+                if time > p[1]:
+                    p[1] = time
 
     a = 1
     for p in packages:
@@ -224,6 +219,7 @@ def current_emerges(f):
             main_loop(f, name, True)
 
 
+
 def main_loop(f, package, silent):
     global emerge_number
     emerge_number = 0
@@ -275,7 +271,7 @@ def main(status):
     f = open_log()
 
     if status == 'current':
-        current_packages = current_emerges(f)
+        list_emerge_processes(f)
         return
     else:
         pass