Advanced search parameters added. pisi can now search only by name, summary
or description of a package. (Jérôme Schneider)
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
2009-08-12 Jérôme Schneider <jerome.schneider@gmail.com>
|
||||
* Advanced search parameters added. pisi can now search only by name, summary
|
||||
or description of a package.
|
||||
|
||||
2009-08-11 Serdar Dalgıç <dalgic.srdr@gmail.com>
|
||||
* (cli/build.py): pisi build command now works in debug mode unless -q
|
||||
or --quiet parameter is passed.
|
||||
|
||||
+15
-3
@@ -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)
|
||||
|
||||
|
||||
+18
-4
@@ -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 = '<Summary xml:lang=.(%s|en).>.*?%s.*?</Summary>'
|
||||
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
||||
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
|
||||
|
||||
|
||||
+18
-4
@@ -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 = '<Summary xml:lang=.(%s|en).>.*?%s.*?</Summary>'
|
||||
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
||||
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
|
||||
|
||||
|
||||
+18
-4
@@ -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 = '<Summary xml:lang=.(%s|en).>.*?%s.*?</Summary>'
|
||||
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user