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:
+11
-5
@@ -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)
|
||||
|
||||
+5
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user