From 3216586d1a63bac9801428be8b34317f5a983768 Mon Sep 17 00:00:00 2001 From: Faik Uygur Date: Wed, 12 Aug 2009 06:12:26 +0000 Subject: [PATCH] =?UTF-8?q?Advanced=20search=20parameters=20added.=20pisi?= =?UTF-8?q?=20can=20now=20search=20only=20by=20name,=20summary=20or=20desc?= =?UTF-8?q?ription=20of=20a=20package.=20(J=C3=A9r=C3=B4me=20Schneider)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ChangeLog | 4 ++++ pisi/cli/search.py | 18 +++++++++++++++--- pisi/db/installdb.py | 22 ++++++++++++++++++---- pisi/db/packagedb.py | 22 ++++++++++++++++++---- pisi/db/sourcedb.py | 22 ++++++++++++++++++---- 5 files changed, 73 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93833249..d13bc142 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-08-12 Jérôme Schneider + * Advanced search parameters added. pisi can now search only by name, summary + or description of a package. + 2009-08-11 Serdar Dalgıç * (cli/build.py): pisi build command now works in debug mode unless -q or --quiet parameter is passed. diff --git a/pisi/cli/search.py b/pisi/cli/search.py index 46f1f517..fc60eba5 100644 --- a/pisi/cli/search.py +++ b/pisi/cli/search.py @@ -49,6 +49,12 @@ database. default=False, help=_("Search in installdb")) group.add_option("-s", "--sourcedb", action="store_true", default=False, help=_("Search in sourcedb")) + group.add_option("--name", action="store_true", + default=False, help=_('Search in the package name')) + group.add_option("--summary", action="store_true", + default=False, help=_('Search in the package summary')) + group.add_option("--description", action="store_true", + default=False, help=_('Search in the package description')) self.parser.add_option_group(group) def run(self): @@ -62,20 +68,26 @@ database. replace = re.compile("(%s)" % "|".join(self.args), re.I) lang = ctx.get_option('language') repo = ctx.get_option('repository') + name = ctx.get_option('name') + summary = ctx.get_option('summary') + desc = ctx.get_option('description') + fields = None + if name or summary or desc: + fields = {'name': name, 'summary': summary, 'desc': desc} if ctx.get_option('installdb'): db = pisi.db.installdb.InstallDB() - pkgs = db.search_package(self.args, lang) + pkgs = db.search_package(self.args, lang, fields) get_info = db.get_package get_name_sum = lambda pkg:(pkg.name, pkg.summary) elif ctx.get_option('sourcedb'): db = pisi.db.sourcedb.SourceDB() - pkgs = db.search_spec(self.args, lang, repo) + pkgs = db.search_spec(self.args, lang, repo, fields) get_info = db.get_spec get_name_sum = lambda pkg:(pkg.source.name, pkg.source.summary) else: db = pisi.db.packagedb.PackageDB() - pkgs = db.search_package(self.args, lang, repo) + pkgs = db.search_package(self.args, lang, repo, fields) get_info = db.get_package get_name_sum = lambda pkg:(pkg.name, pkg.summary) diff --git a/pisi/db/installdb.py b/pisi/db/installdb.py index 914c1b52..00f1653f 100644 --- a/pisi/db/installdb.py +++ b/pisi/db/installdb.py @@ -144,17 +144,31 @@ class InstallDB(lazydb.LazyDB): files = self.get_files(package) return filter(lambda x: x.type == 'config', files.list) - def search_package(self, terms, lang=None): + def search_package(self, terms, lang=None, fields=None): + """ + fields (dict) : looks for terms in the fields which are marked as True + If the fields is equal to None this method will search in all fields + + example : + if fields is equal to : {'name': True, 'summary': True, 'desc': False} + This method will return only package that contents terms in the package + name or summary + """ resum = '.*?%s.*?' redesc = '.*?%s.*?' + if not fields: + fields = {'name': True, 'summary': True, 'desc': True} if not lang: lang = pisi.pxml.autoxml.LocalText.get_lang() found = [] for name in self.list_installed(): xml = open(os.path.join(self.package_path(name), ctx.const.metadata_xml)).read() - if terms == filter(lambda term: re.compile(term, re.I).search(name) or \ - re.compile(resum % (lang, term), re.I).search(xml) or \ - re.compile(redesc % (lang, term), re.I).search(xml), terms): + if terms == filter(lambda term: (fields['name'] and \ + re.compile(term, re.I).search(name)) or \ + (fields['summary'] and \ + re.compile(resum % (lang, term), re.I).search(xml)) or \ + (fields['desc'] and \ + re.compile(redesc % (lang, term), re.I).search(xml)), terms): found.append(name) return found diff --git a/pisi/db/packagedb.py b/pisi/db/packagedb.py index 02c1e3ad..ba5f8130 100644 --- a/pisi/db/packagedb.py +++ b/pisi/db/packagedb.py @@ -98,16 +98,30 @@ class PackageDB(lazydb.LazyDB): found.append(name) return found - def search_package(self, terms, lang=None, repo=None): + def search_package(self, terms, lang=None, repo=None, fields=None): + """ + fields (dict) : looks for terms in the fields which are marked as True + If the fields is equal to None the method will search on all fields + + example : + if fields is equal to : {'name': True, 'summary': True, 'desc': False} + This method will return only package that contents terms in the package + name or summary + """ resum = '.*?%s.*?' redesc = '.*?%s.*?' if not lang: lang = pisi.pxml.autoxml.LocalText.get_lang() + if not fields: + fields = {'name': True, 'summary': True, 'desc': True} found = [] for name, xml in self.pdb.get_items_iter(repo): - if terms == filter(lambda term: re.compile(term, re.I).search(name) or \ - re.compile(resum % (lang, term), re.I).search(xml) or \ - re.compile(redesc % (lang, term), re.I).search(xml), terms): + if terms == filter(lambda term: (fields['name'] and \ + re.compile(term, re.I).search(name)) or \ + (fields['summary'] and \ + re.compile(resum % (lang, term), re.I).search(xml)) or \ + (fields['desc'] and \ + re.compile(redesc % (lang, term), re.I).search(xml)), terms): found.append(name) return found diff --git a/pisi/db/sourcedb.py b/pisi/db/sourcedb.py index f68b87a1..8175a14d 100644 --- a/pisi/db/sourcedb.py +++ b/pisi/db/sourcedb.py @@ -82,16 +82,30 @@ class SourceDB(lazydb.LazyDB): spec, repo = self.get_spec_repo(name, repo) return spec - def search_spec(self, terms, lang=None, repo=None): + def search_spec(self, terms, lang=None, repo=None, fields=None): + """ + fields (dict) : looks for terms in the fields which are marked as True + If the fields is equal to None this method will search in all fields + + example : + if fields is equal to : {'name': True, 'summary': True, 'desc': False} + This method will return only package that contents terms in the package + name or summary + """ resum = '.*?%s.*?' redesc = '.*?%s.*?' + if not fields: + fields = {'name': True, 'summary': True, 'desc': True} if not lang: lang = pisi.pxml.autoxml.LocalText.get_lang() found = [] for name, xml in self.sdb.get_items_iter(repo): - if terms == filter(lambda term: re.compile(term, re.I).search(name) or \ - re.compile(resum % (lang, term), re.I).search(xml) or \ - re.compile(redesc % (lang, term), re.I).search(xml), terms): + if terms == filter(lambda term: (fields['name'] and \ + re.compile(term, re.I).search(name)) or \ + (fields['summary'] and \ + re.compile(resum % (lang, term), re.I).search(xml)) or \ + (fields['desc'] and \ + re.compile(redesc % (lang, term), re.I).search(xml)), terms): found.append(name) return found