diff --git a/pisi/cli/commands.py b/pisi/cli/commands.py index 934bcdba..7c87ed4f 100644 --- a/pisi/cli/commands.py +++ b/pisi/cli/commands.py @@ -903,20 +903,26 @@ Finds the installed package which contains the specified file. def options(self): self.parser.add_option("-l", "--long", action="store_true", default=False, help="show in long format") + self.parser.add_option("-f", "--fuzzy", action="store_true", + default=False, help=_("fuzzy search")) def search_exact(path): - import os.path - + files = [] path = path.lstrip('/') #FIXME: this shouldn't be necessary :/ - files = ctx.filesdb.get_files(path) + + if not ctx.config.options.fuzzy: + if ctx.filesdb.has_file(path): + files.append(ctx.filesdb.get_file(path)) + else: + files = ctx.filesdb.get_files(path) if files: for (pkg_name, file_info) in files: - #FIXME: there can be a prettier info line + #FIXME: files of the same package can be grouped under package name ctx.ui.info(_('Package: %s has File: %s') % (pkg_name, file_info.path)) if ctx.config.options.long: ctx.ui.info(_('Type: %s, Hash: %s') % (file_info.type, - file_info.hash) ) + file_info.hash)) else: ctx.ui.error(_('Path %s does not belong to an installed package') % path) search_exact=staticmethod(search_exact) diff --git a/pisi/files.py b/pisi/files.py index dedfc0d9..0e16c2d5 100644 --- a/pisi/files.py +++ b/pisi/files.py @@ -68,12 +68,13 @@ class FilesDB(shelve.LockedDBShelf): else: return self[path] - def get_files(self, file): - infos = [] - file = str(file) + def get_files(self, glob): + import fnmatch + glob = str(glob) + infos = [] for key in self.keys(): - if key.find(file) >= 0: + if fnmatch.fnmatch(key, glob): infos.append(self[key]) return infos