]> git.itanic.dy.fi Git - emerge-timer/commitdiff
List current emerges
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Sun, 3 Jul 2011 10:40:17 +0000 (13:40 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Sun, 3 Jul 2011 10:46:27 +0000 (13:46 +0300)
This feature is still largely unfinished and buggy as it also takes
into account those emerges that have been terminated prematurely. You
can access this feature by not giving any commandline arguments.

emerge-timer.py

index d9d588e496c56aab8616f1a0bf48277eebf05d4c..3e685de1b057fcb6c8fd7e8dc2af39c25bfb9aac 100755 (executable)
@@ -166,20 +166,50 @@ def open_log():
         return f
 
 
-def get_opts():
-    try:
-        package_name = sys.argv[1]
-    except IndexError:
-        f.close()
-        sys.exit(1)
-    finally:
-        return package_name
-
-
-def main():
+def main(status):
     global emerge_number
+
     f = open_log()
-    package_name = get_opts()
+
+    if status == 'current':
+        packages = []
+        for line in f:
+            if ((">>>" in line) and ("emerge" in line)):
+                part = line.partition(' ')
+
+                time = float(part[0].strip(":"))
+
+                # 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.append((part[0], time))
+
+            for p in packages:
+                if ((p[0] in line) and ('completed emerge' in line)):
+                    packages.remove(p)
+
+
+        a = 1
+        for p in packages:
+            now = datetime.datetime.today()
+            timestamp = datetime.datetime.fromtimestamp(p[1])
+            difference = now - timestamp
+
+            if difference.total_seconds() < 12*60*60:
+                if a:
+                    print("Currently emerging: ")
+                    a = 0
+                print("\t" + green_start + p[0] + color_stop)
+
+        return
+
+    else:
+        pass
+
 
     get_package(package_name)
 
@@ -223,7 +253,12 @@ def main():
 
 if __name__ == "__main__":
 
-    main()
+    if len(sys.argv) > 1:
+        package_name = sys.argv[1]
+        main(0)
+    else:
+        main('current')
+        sys.exit(1)
 
     print_times(times)