From: genone Date: Fri, 23 Jan 2004 02:51:09 +0000 (-0000) Subject: catch KeyError and ValueError thrown by portage on invalid/ambiguous package names X-Git-Tag: gentoolkit-0.2.4.3~434 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=600418b2d4314cfb6ae6ca210de944f7b9e3d9cf;p=gentoolkit.git catch KeyError and ValueError thrown by portage on invalid/ambiguous package names svn path=/; revision=68 --- diff --git a/trunk/src/equery/equery b/trunk/src/equery/equery index b991393..099bc33 100755 --- a/trunk/src/equery/equery +++ b/trunk/src/equery/equery @@ -920,7 +920,22 @@ def parseArgs(args): if __name__ == "__main__": (cmd, local_opts) = parseArgs(sys.argv[1:]) if cmd: - cmd.perform(local_opts) + try: + cmd.perform(local_opts) + except KeyError, e: + print red("!!!"), "Invalid syntax: missing operator" + print red("!!!"), "If you want only specific versions please use one of" + print red("!!!"), "the following operators as prefix for the package name:" + print red("!!!"), " > >= = <= <" + print red("!!!"), "Example to only match gcc versions greater or equal 3.2:" + print red("!!!"), " >=sys-devel/gcc-3.2" + sys.exit(2) + except ValueError, epkg: + print red("!!!"), "Ambiguous package name \"%s\"" % query + print red("!!!"), "Please use one of the following long names:" + for p in epkg[0]: + print red("!!!"), " "+p + sys.exit(2) else: print "No command or unknown command given" printUsage() diff --git a/trunk/src/etcat/etcat b/trunk/src/etcat/etcat index 99d0739..e5e726a 100755 --- a/trunk/src/etcat/etcat +++ b/trunk/src/etcat/etcat @@ -222,8 +222,7 @@ def output_log(lines, package_ver=""): # | Print out the ChangeLog entry for package[-version] | # `-------------------------------------------------------' -def changes(query): - matches=gentoolkit.find_packages(query) +def changes(query, matches): if not report_matches(query,matches,installed_only=0): return @@ -242,8 +241,7 @@ def changes(query): # | installed status. | # `-------------------------------------------------------' -def versions(query): - matches = gentoolkit.find_packages(query) +def versions(query, matches): if not report_matches(query,matches): return @@ -299,10 +297,7 @@ def versions(query): # +-------------------------------------------------------+ # | Just uses the new IUSE parameter in ebuilds | # `-------------------------------------------------------' -def uses(query): - - matches = gentoolkit.find_packages(query) - +def uses(query, matches): useflags = gentoolkit.settings["USE"].split() usedesc = {} uselocaldesc = {} @@ -409,8 +404,7 @@ def uses(query): # | Naive graphing of dependencies # `-------------------------------------------------------' -def graph(query): - matches = gentoolkit.find_packages(query) +def graph(query, matches): if not report_matches(query, matches): return @@ -447,13 +441,13 @@ def rgraph(pkg,level=0,pkgtbl=[],suffix=""): # | Find what packages require a given package name | # `-------------------------------------------------------' -def depends(query): +def depends(query, matches): print "[ Results for search key : " + white(query) + " ]" isdepend = gentoolkit.split_package_name(query) - for pkg in gentoolkit.find_all_packages(): + for pkg in matches: if pkg.is_installed(): deps = pkg.get_runtime_deps() for x in deps: @@ -611,7 +605,7 @@ def main(): # delegates the commandline stuff to functions pointer = 2 # short/long opts mapping - shortopts = map(lambda x: "-" + x[0], options.values()) + shortopts = ["-"+x[0] for x in options.values()] short2long = {} for k,v in options.items(): short2long[v[0]] = k @@ -634,8 +628,24 @@ def main(): help() sys.exit(1) else: + try: + matches = gentoolkit.find_packages(query) + except KeyError, e: + print red("!!!"), "Invalid syntax: missing operator" + print red("!!!"), "If you want only specific versions please use one of" + print red("!!!"), "the following operators as prefix for the package name:" + print red("!!!"), " > >= = <= <" + print red("!!!"), "Example to only match gcc versions greater or equal 3.2:" + print red("!!!"), " >=sys-devel/gcc-3.2" + sys.exit(2) + except ValueError, epkg: + print red("!!!"), "Ambiguous package name \"%s\"" % query + print red("!!!"), "Please use one of the following long names:" + for p in epkg[0]: + print red("!!!"), " "+p + sys.exit(2) function = globals()[action] - function(query) + function(query, matches) if __name__ == "__main__": try: