From: Esko Kokkonen Date: Mon, 29 Aug 2011 15:05:21 +0000 (+0300) Subject: Improve current process handling X-Git-Url: http://git.itanic.dy.fi/?p=emerge-timer;a=commitdiff_plain;h=2e633a16d62ef1d6bf3380c55157f618200fad85 Improve current process handling Use the same method of getting the package name as in the pretended function. Now the print_current_emerges function is simplified by not having to go through the list of all the package names. --- diff --git a/emerge-timer.py b/emerge-timer.py index c2ef444..81810ce 100755 --- a/emerge-timer.py +++ b/emerge-timer.py @@ -250,21 +250,28 @@ def list_emerge_processes(f): if (("ebuild.sh" in i) and ("/bin/bash" not in i)): pack = i.partition('[')[2].partition(']')[0] - packages.append([pack, 12*3600]) + version = pack.partition('/')[2].partition('-')[2] + + while not version[0].isdigit(): + version = version.partition('-')[2] + + package_name = pack[:-len(version)-1] + + packages.append([package_name, '-'+version, 12*3600]) for line in f: if ((">>>" in line) and ("emerge" in line)): for p in packages: - if (p[0] in line): + if (p[0]+p[1] in line): time = float(line.partition(' ')[0].strip(":")) timestamp = datetime.datetime.fromtimestamp(time) difference = (now - timestamp).total_seconds() - if difference < p[1]: - p[1] = difference + if difference < p[2]: + p[2] = difference if len(packages) == 0: @@ -280,28 +287,27 @@ def print_current_emerges(f, packages): """Print the current packages that are being merged with the current emerge time.""" - all_packages = list_all_packages() print("Currently emerging: ") for p in packages: - print("\t" + green_start + p[0] + color_stop), + print("\t" + green_start + p[0] + p[1] + color_stop), print("\n\t current emerge time:\t"), - organize_times(p[1]) + organize_times(p[2]) print - - for i in all_packages: - if i in p[0]: - average_time = main_loop(f, i, True) + average_time = main_loop(f, p[0], True) if average_time != 0: print("\n\t " + '-'*45 + "\n\t time to finish: \t"), - if (average_time - p[1]) < 0: + + if (average_time - p[2]) < 0: print(green_start + "Any time now" + color_stop), + else: - organize_times(average_time - p[1]) + organize_times(average_time - p[2]) + print "\n"