]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Change the package naming function
authorEsko Kokkonen <esko@localhost.(none)>
Wed, 8 Jun 2011 12:42:20 +0000 (15:42 +0300)
committerEsko Kokkonen <esko@localhost.(none)>
Wed, 8 Jun 2011 12:43:40 +0000 (15:43 +0300)
Use the /usr/portage/ directory structure to find out of the correct package name

emerge-timer.py

index d8f59289b61645ba19c6492874fc6ff67988b8ce..a79f86dcf6fe71d6bcb53fe4240d91eba0f5a5d5 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import sys, subprocess, datetime
+import sys, subprocess, datetime, os
 
 try:
     f = open('/var/log/emerge.log', 'r')
@@ -48,17 +48,17 @@ def date_printer(package, time1, time2):
     return date
 
 
-def get_package(string, name):
+def get_package(name):
     global package
-    newstring = string.partition(" ")
+    dirlist = os.listdir('/usr/portage/')
 
-    while name not in newstring[0]:
-        newstring = newstring[2].partition(" ")
+    for i in dirlist:
+        directory = '/usr/portage/' + i
+        if os.path.isdir(directory):
+            dirs = os.listdir(directory)
+            if name in dirs:
+                package = i + '/' + name
 
-    while name in newstring[0]:
-        newstring = newstring[0].rpartition("-")
-
-    package = newstring[0] + newstring[1] + newstring[2]
 
 def print_times(times):
     times.sort()
@@ -91,8 +91,10 @@ def print_times(times):
         print "s emerging", package
 
 
+get_package(package_name)
+
 for line in f:
-    if package_name in line:
+    if package in line:
         if (">>>" in line) and ("emerge" in line):
             get_package(line, package_name)
             time = get_time(line, 1)