]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Add get_package function
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Fri, 26 Aug 2011 09:39:25 +0000 (12:39 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Fri, 26 Aug 2011 09:39:25 +0000 (12:39 +0300)
emerge-timer.py

index 18e3a8a1b78c132a964d186b7683a2bdac0110dc..86db0660dde4df10a8bb506d17c647fe704445bc 100755 (executable)
@@ -126,18 +126,64 @@ def search_log_for_package(user_package):
                     packages[0].add_version(version, emerge_time, start_time)
 
 
+def get_package(name):
+    """Take the user-input package name and search for it
+    in PORTDIR. """
 
-def print_stuff():
-    for p in packages:
-        p.print_versions()
+    dirlist = os.listdir(PORTDIR)
+    possible_package = []
+
+
+    # If the given name is in the format xxx/zzz
+    # assume that xxx is the package group
+    if '/' in name:
+        group = name.partition('/')[0]
+        pkg = name.partition('/')[2]
+        directory = PORTDIR + group
+
+        if group in dirlist:
+            dirs = os.listdir(directory)
+            if pkg in dirs:
+                possible_package.append(name)
+
+
+    # Go through the directory listing searching for anything
+    # that matches the given name
+    for i in dirlist:
+        directory = PORTDIR + i
+        if os.path.isdir(directory):
+            dirs = os.listdir(directory)
+            if name in dirs:
+                possible_package.append(i + '/' + name)
+
+
+    if len(possible_package) > 1:
+        print("Multiple packages found for '" + name + "'.")
+        print("Possible packages: ")
+        for value in possible_package:
+            print("\t" + value)
+
+
+    elif len(possible_package) == 1:
+        package = possible_package[0]
+        return package
+
+
+    else:
+        print("No package '" + name + "' found")
+
+
+    sys.exit(1)
 
 
 
 def main(status, user_package=None):
 
     if status == "package":
+        user_package = get_package(user_package)
+
         search_log_for_package(user_package)
-        print_stuff()
+        packages[0].print_versions()
 
 
     elif status == "current":