def test_RPMHeaderListLoader_searcher(self): """ Ensure getPathList is working correctly with indexes. """ # Just assert it's called at all. get_header_filenames_mock = self.mocker.replace(get_header_filenames) get_header_filenames_mock(ANY) self.mocker.passthrough() self.mocker.replay() searcher = Searcher() searcher.addPath("/tmp/file1") cache = Cache() loader = RPMDirLoader(TESTDATADIR + "/rpm", "name1-version1-release1.noarch.rpm") loader.setCache(cache) loader.load() loader.search(searcher) results = searcher.getResults() self.assertEquals(len(results), 1) self.assertEquals(results[0][0], 1.0) self.assertEquals(results[0][1].name, "name1")
def search(self, s, cutoff=1.00, suggestioncutoff=0.70, globcutoff=1.00, globsuggestioncutoff=0.95, addprovides=True): ratio = 0 results = [] suggestions = [] objects = [] # If we find packages with exactly the given # name or name-version, use them. for pkg in self._cache.getPackages(s): if pkg.name == s or "%s-%s" % (pkg.name, pkg.version) == s: objects.append((1.0, pkg)) if not objects: if "*" in s: cutoff = globcutoff suggestioncutoff = globsuggestioncutoff searcher = Searcher() searcher.addAuto(s, suggestioncutoff) if addprovides: searcher.addProvides(s, suggestioncutoff) self._cache.search(searcher) objects = searcher.getResults() if objects: bestratio = objects[0][0] if bestratio < cutoff: suggestions = objects else: for i in range(len(objects)): ratio, obj = objects[i] if ratio == bestratio: results.append(obj) else: suggestions = objects[i:] break if results: ratio = bestratio return ratio, results, suggestions
def search(self, s, cutoff=1.00, suggestioncutoff=0.70, globcutoff=1.00, globsuggestioncutoff=0.95, addprovides=True): ratio = 0 results = [] suggestions = [] objects = [] # If we find packages with exactly the given # name, name-version, or name@arch, use them. s_name = s if "@" in s: s_name = s.split("@")[0] for pkg in self._cache.getPackages(s_name): if pkg.name == s or "%s-%s" % (pkg.name, pkg.version) == s \ or "%s@%s" % (pkg.name, pkg.version.split('@')[1]) == s: objects.append((1.0, pkg)) if not objects: if "*" in s: cutoff = globcutoff suggestioncutoff = globsuggestioncutoff searcher = Searcher() searcher.addAuto(s, suggestioncutoff) if addprovides: searcher.addProvides(s, suggestioncutoff) self._cache.search(searcher) objects = searcher.getResults() if objects: bestratio = objects[0][0] if bestratio < cutoff: suggestions = objects else: for i in range(len(objects)): ratio, obj = objects[i] if ratio == bestratio: results.append(obj) else: suggestions = objects[i:] break if results: ratio = bestratio return ratio, results, suggestions
def refreshPackages(self): if not self._ctrl: return self.setBusy(True) tree = sysconf.get("package-tree", "groups") ctrl = self._ctrl changeset = self._changeset if self._searchbar.isVisible() and \ self._searchentry.text(): # temporary searcher = Searcher() dosearch = False if self._searchdesc.isChecked(): text = self._searchentry.text() if text: text = str(text).strip() dosearch = True searcher.addDescription(text) searcher.addSummary(text) else: try: text = self._searchentry.text() tokens = shlex.split(str(text)) except ValueError: pass else: if tokens: dosearch = True for tok in tokens: if searcher.hasAutoMeaning(tok): searcher.addAuto(tok) else: searcher.addNameVersion("*%s*" % tok) packages = [] if dosearch: self._ctrl.getCache().search(searcher) for ratio, obj in searcher.getResults(): if isinstance(obj, Package): packages.append(obj) else: packages.extend(obj.packages) else: packages = ctrl.getCache().getPackages() filters = self._filters if filters: if "hide-non-upgrades" in filters: newpackages = {} for pkg in packages: if pkg.installed: upgpkgs = {} try: for prv in pkg.provides: for upg in prv.upgradedby: for upgpkg in upg.packages: if upgpkg.installed: raise StopIteration upgpkgs[upgpkg] = True except StopIteration: pass else: newpackages.update(upgpkgs) packages = newpackages.keys() if "hide-uninstalled" in filters: packages = [x for x in packages if x.installed] if "hide-unmarked" in filters: packages = [x for x in packages if x in changeset] if "hide-installed" in filters: packages = [x for x in packages if not x.installed] if "hide-unlocked" in filters: packages = pkgconf.filterByFlag("lock", packages) if "hide-requested" in filters: packages = pkgconf.filterByFlag("auto", packages) if "hide-old" in filters: packages = pkgconf.filterByFlag("new", packages) if tree == "groups": groups = {} done = {} for pkg in packages: lastgroup = None for loader in pkg.loaders: info = loader.getInfo(pkg) group = info.getGroup() donetuple = (group, pkg) if donetuple not in done: done[donetuple] = True if group in groups: groups[group].append(pkg) else: groups[group] = [pkg] elif tree == "channels": groups = {} done = {} for pkg in packages: for loader in pkg.loaders: channel = loader.getChannel() group = channel.getName() or channel.getAlias() donetuple = (group, pkg) if donetuple not in done: done[donetuple] = True if group in groups: groups[group].append(pkg) else: groups[group] = [pkg] elif tree == "channels-groups": groups = {} done = {} for pkg in packages: for loader in pkg.loaders: channel = loader.getChannel() group = channel.getName() or channel.getAlias() subgroup = loader.getInfo(pkg).getGroup() donetuple = (group, subgroup, pkg) if donetuple not in done: done[donetuple] = True if group in groups: if subgroup in groups[group]: groups[group][subgroup].append(pkg) else: groups[group][subgroup] = [pkg] else: groups[group] = {subgroup: [pkg]} else: groups = packages self._pv.setPackages(groups, changeset, keepstate=True) self.setBusy(False)
def refreshPackages(self): if not self._ctrl: return self.setBusy(True) tree = sysconf.get("package-tree", "groups") ctrl = self._ctrl changeset = self._changeset self._pg.parent.set_property('visible', tree == "separate-groups") if self._pg.get_property('visible'): model = self._pg.get_model() if not model: packages = ctrl.getCache().getPackages() packagegroups = {} for pkg in packages: for loader in pkg.loaders: info = loader.getInfo(pkg) group = info.getGroup() if group in packagegroups: packagegroups[group] += 1 else: packagegroups[group] = 1 groups = [] names = {} all = "%s (%d)" % (_("All"), len(packages)) for group, count in packagegroups.iteritems(): displayicon = None displayname = "%s (%d)" % (group, count) groups.append(displayname) names[displayname] = group groups.sort() model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self._pg.set_model(model) iter = model.append() model.set(iter, 0, None) model.set(iter, 1, all) self._pg.get_selection().select_iter(iter) for group in groups: iter = model.append() model.set(iter, 0, names[group]) model.set(iter, 1, group) self._pg.queue_draw() columns = sysconf.get("package-columns", "name,version") self._pv.setVisibleColumns(columns.split(",")) if self._searchbar.get_property("visible"): searcher = Searcher() dosearch = False if self._searchdesc.get_active(): text = self._searchentry.get_text().strip() if text: dosearch = True searcher.addDescription(text) searcher.addSummary(text) else: try: tokens = shlex.split(self._searchentry.get_text()) except ValueError: pass else: if tokens: dosearch = True for tok in tokens: if searcher.hasAutoMeaning(tok): searcher.addAuto(tok) else: searcher.addNameVersion("*%s*" % tok) packages = [] if dosearch: self._ctrl.getCache().search(searcher) for ratio, obj in searcher.getResults(): if isinstance(obj, Package): packages.append(obj) else: packages.extend(obj.packages) elif isinstance(self._searchbar, gtk.ToolItem): packages = ctrl.getCache().getPackages() else: packages = ctrl.getCache().getPackages() filters = self._filters if filters: if "hide-non-upgrades" in filters: newpackages = {} for pkg in packages: if pkg.installed: upgpkgs = {} try: for prv in pkg.provides: for upg in prv.upgradedby: for upgpkg in upg.packages: if upgpkg.installed: raise StopIteration upgpkgs[upgpkg] = True except StopIteration: pass else: newpackages.update(upgpkgs) packages = newpackages.keys() if "hide-non-newest" in filters: newest = {} for pkg in packages: if pkg.name in newest: if pkg > newest[pkg.name]: newest[pkg.name] = pkg else: newest[pkg.name] = pkg packages = [pkg for pkg in packages if pkg == newest[pkg.name]] if "hide-uninstalled" in filters: packages = [x for x in packages if x.installed] if "hide-unmarked" in filters: packages = [x for x in packages if x in changeset] if "hide-installed" in filters: packages = [x for x in packages if not x.installed] if "hide-unlocked" in filters: packages = pkgconf.filterByFlag("lock", packages) if "hide-requested" in filters: packages = pkgconf.filterByFlag("auto", packages) if "hide-old" in filters: packages = pkgconf.filterByFlag("new", packages) if tree == "groups": groups = {} done = {} for pkg in packages: lastgroup = None for loader in pkg.loaders: info = loader.getInfo(pkg) group = info.getGroup() donetuple = (group, pkg) if donetuple not in done: done[donetuple] = True if group in groups: groups[group].append(pkg) else: groups[group] = [pkg] elif tree == "separate-groups": showgroups = {} selection = self._pg.get_selection() model, paths = selection.get_selected_rows() for path in paths: iter = model.get_iter(path) value = model.get_value(iter, 0) showgroups[value] = True if showgroups and None not in showgroups: newpackages = [] done = {} for pkg in packages: for loader in pkg.loaders: info = loader.getInfo(pkg) group = info.getGroup() donetuple = (group, pkg) if donetuple not in done: done[donetuple] = True if group in showgroups: newpackages.append(pkg) groups = newpackages else: groups = packages elif tree == "channels": groups = {} done = {} for pkg in packages: for loader in pkg.loaders: channel = loader.getChannel() group = channel.getName() or channel.getAlias() donetuple = (group, pkg) if donetuple not in done: done[donetuple] = True if group in groups: groups[group].append(pkg) else: groups[group] = [pkg] elif tree == "channels-groups": groups = {} done = {} for pkg in packages: for loader in pkg.loaders: channel = loader.getChannel() group = channel.getName() or channel.getAlias() subgroup = loader.getInfo(pkg).getGroup() donetuple = (group, subgroup, pkg) if donetuple not in done: done[donetuple] = True if group in groups: if subgroup in groups[group]: groups[group][subgroup].append(pkg) else: groups[group][subgroup] = [pkg] else: groups[group] = {subgroup: [pkg]} else: groups = packages self._pv.setPackages(groups, changeset, keepstate=True) packages = ctrl.getCache().getPackages() self.showStatus(_("%d packages, %d installed") % (len(packages), len([pkg for pkg in packages if pkg.installed]))) self.setBusy(False)
def test_group(self): searcher = Searcher() searcher.addGroup("foo")