From 1f9efffabc1c382abfeccb3ac90d7c1db55f77e3 Mon Sep 17 00:00:00 2001 From: Esko Kokkonen Date: Fri, 26 Aug 2011 12:39:25 +0300 Subject: [PATCH] Add get_package function --- emerge-timer.py | 54 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/emerge-timer.py b/emerge-timer.py index 18e3a8a..86db066 100755 --- a/emerge-timer.py +++ b/emerge-timer.py @@ -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": -- 2.44.0