pisi search-file

* O(1) with default:
  pisi search-file /usr/lib/libstdc++.so.2.9.0
  
* glob support with --fuzzy:
  pisi search-file --fuzzy *libstdc++*
This commit is contained in:
Faik Uygur
2005-11-09 23:04:14 +00:00
parent a11509db79
commit b81adc094e
2 changed files with 16 additions and 9 deletions
+11 -5
View File
@@ -903,20 +903,26 @@ Finds the installed package which contains the specified file.
def options(self): def options(self):
self.parser.add_option("-l", "--long", action="store_true", self.parser.add_option("-l", "--long", action="store_true",
default=False, help="show in long format") 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): def search_exact(path):
import os.path files = []
path = path.lstrip('/') #FIXME: this shouldn't be necessary :/ 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: if files:
for (pkg_name, file_info) in 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)) ctx.ui.info(_('Package: %s has File: %s') % (pkg_name, file_info.path))
if ctx.config.options.long: if ctx.config.options.long:
ctx.ui.info(_('Type: %s, Hash: %s') % (file_info.type, ctx.ui.info(_('Type: %s, Hash: %s') % (file_info.type,
file_info.hash) ) file_info.hash))
else: else:
ctx.ui.error(_('Path %s does not belong to an installed package') % path) ctx.ui.error(_('Path %s does not belong to an installed package') % path)
search_exact=staticmethod(search_exact) search_exact=staticmethod(search_exact)
+5 -4
View File
@@ -68,12 +68,13 @@ class FilesDB(shelve.LockedDBShelf):
else: else:
return self[path] return self[path]
def get_files(self, file): def get_files(self, glob):
infos = [] import fnmatch
file = str(file)
glob = str(glob)
infos = []
for key in self.keys(): for key in self.keys():
if key.find(file) >= 0: if fnmatch.fnmatch(key, glob):
infos.append(self[key]) infos.append(self[key])
return infos return infos