summaryrefslogtreecommitdiff
path: root/trunk/src/equery
diff options
context:
space:
mode:
authorkarltk <karltk@gentoo.org>2004-08-29 20:05:02 +0000
committerkarltk <karltk@gentoo.org>2004-08-29 20:05:02 +0000
commitf919aee06cbb9e0a4d0f55885f19ce5002dae2e8 (patch)
tree06724a75c0e95da9db11e65c42db6a0f875e12e4 /trunk/src/equery
parent4b8d4247d40181f3cf8bdc82242cc628a8ccc109 (diff)
downloadgentoolkit-f919aee06cbb9e0a4d0f55885f19ce5002dae2e8.tar.gz
Added exception checking to CmdBelongs to guard against bad regular expressions.
svn path=/; revision=119
Diffstat (limited to 'trunk/src/equery')
-rwxr-xr-xtrunk/src/equery/equery25
1 files changed, 16 insertions, 9 deletions
diff --git a/trunk/src/equery/equery b/trunk/src/equery/equery
index f9c1382..773a603 100755
--- a/trunk/src/equery/equery
+++ b/trunk/src/equery/equery
@@ -26,6 +26,10 @@ sys.path.insert(0, "/usr/lib/portage/pym")
from output import *
import gentoolkit
+from gentoolkit import warn
+from gentoolkit import error
+from gentoolkit import info
+
# Auxiliary functions
def fileAsStr(name, fdesc, showType=0, showMD5=0, showTimestamp=0):
@@ -220,19 +224,22 @@ class CmdListBelongs(Command):
if cat != "*":
filter_fn = lambda x: x.find(cat+"/")==0
- if Config["verbosityLevel"] >= 3 and not Config["piping"]:
- print "Searching for file '" + query + "' in " + cat + "..."
+ info(3, "Searching for file '" + query + "' in " + cat + "...")
matches = gentoolkit.find_all_installed_packages(filter_fn)
# Act intelligently on the query
- if opts["fullRegex"]:
- rx = re.compile(query)
- elif len(query) and query[0] == "/":
- rx = re.compile("^" + query + "$")
- else:
- rx = re.compile("/" + query + "$")
-
+ try:
+ if opts["fullRegex"]:
+ rx = re.compile(query)
+ elif len(query) and query[0] == "/":
+ rx = re.compile("^" + query + "$")
+ else:
+ rx = re.compile("/" + query + "$")
+ except:
+ error("The query '" + query + "' does not appear to be a valid regular expression")
+ sys.exit(-2)
+
found = 0
for pkg in matches:
cnt = pkg.get_contents()