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>
|
2009-08-11 Serdar Dalgıç <dalgic.srdr@gmail.com>
|
||||||
* (cli/build.py): pisi build command now works in debug mode unless -q
|
* (cli/build.py): pisi build command now works in debug mode unless -q
|
||||||
or --quiet parameter is passed.
|
or --quiet parameter is passed.
|
||||||
|
|||||||
+15
-3
@@ -49,6 +49,12 @@ database.
|
|||||||
default=False, help=_("Search in installdb"))
|
default=False, help=_("Search in installdb"))
|
||||||
group.add_option("-s", "--sourcedb", action="store_true",
|
group.add_option("-s", "--sourcedb", action="store_true",
|
||||||
default=False, help=_("Search in sourcedb"))
|
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)
|
self.parser.add_option_group(group)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -62,20 +68,26 @@ database.
|
|||||||
replace = re.compile("(%s)" % "|".join(self.args), re.I)
|
replace = re.compile("(%s)" % "|".join(self.args), re.I)
|
||||||
lang = ctx.get_option('language')
|
lang = ctx.get_option('language')
|
||||||
repo = ctx.get_option('repository')
|
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'):
|
if ctx.get_option('installdb'):
|
||||||
db = pisi.db.installdb.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_info = db.get_package
|
||||||
get_name_sum = lambda pkg:(pkg.name, pkg.summary)
|
get_name_sum = lambda pkg:(pkg.name, pkg.summary)
|
||||||
elif ctx.get_option('sourcedb'):
|
elif ctx.get_option('sourcedb'):
|
||||||
db = pisi.db.sourcedb.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_info = db.get_spec
|
||||||
get_name_sum = lambda pkg:(pkg.source.name, pkg.source.summary)
|
get_name_sum = lambda pkg:(pkg.source.name, pkg.source.summary)
|
||||||
else:
|
else:
|
||||||
db = pisi.db.packagedb.PackageDB()
|
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_info = db.get_package
|
||||||
get_name_sum = lambda pkg:(pkg.name, pkg.summary)
|
get_name_sum = lambda pkg:(pkg.name, pkg.summary)
|
||||||
|
|
||||||
|
|||||||
+18
-4
@@ -144,17 +144,31 @@ class InstallDB(lazydb.LazyDB):
|
|||||||
files = self.get_files(package)
|
files = self.get_files(package)
|
||||||
return filter(lambda x: x.type == 'config', files.list)
|
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>'
|
resum = '<Summary xml:lang=.(%s|en).>.*?%s.*?</Summary>'
|
||||||
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
||||||
|
if not fields:
|
||||||
|
fields = {'name': True, 'summary': True, 'desc': True}
|
||||||
if not lang:
|
if not lang:
|
||||||
lang = pisi.pxml.autoxml.LocalText.get_lang()
|
lang = pisi.pxml.autoxml.LocalText.get_lang()
|
||||||
found = []
|
found = []
|
||||||
for name in self.list_installed():
|
for name in self.list_installed():
|
||||||
xml = open(os.path.join(self.package_path(name), ctx.const.metadata_xml)).read()
|
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 \
|
if terms == filter(lambda term: (fields['name'] and \
|
||||||
re.compile(resum % (lang, term), re.I).search(xml) or \
|
re.compile(term, re.I).search(name)) or \
|
||||||
re.compile(redesc % (lang, term), re.I).search(xml), terms):
|
(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)
|
found.append(name)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
|||||||
+18
-4
@@ -98,16 +98,30 @@ class PackageDB(lazydb.LazyDB):
|
|||||||
found.append(name)
|
found.append(name)
|
||||||
return found
|
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>'
|
resum = '<Summary xml:lang=.(%s|en).>.*?%s.*?</Summary>'
|
||||||
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
||||||
if not lang:
|
if not lang:
|
||||||
lang = pisi.pxml.autoxml.LocalText.get_lang()
|
lang = pisi.pxml.autoxml.LocalText.get_lang()
|
||||||
|
if not fields:
|
||||||
|
fields = {'name': True, 'summary': True, 'desc': True}
|
||||||
found = []
|
found = []
|
||||||
for name, xml in self.pdb.get_items_iter(repo):
|
for name, xml in self.pdb.get_items_iter(repo):
|
||||||
if terms == filter(lambda term: re.compile(term, re.I).search(name) or \
|
if terms == filter(lambda term: (fields['name'] and \
|
||||||
re.compile(resum % (lang, term), re.I).search(xml) or \
|
re.compile(term, re.I).search(name)) or \
|
||||||
re.compile(redesc % (lang, term), re.I).search(xml), terms):
|
(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)
|
found.append(name)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
|||||||
+18
-4
@@ -82,16 +82,30 @@ class SourceDB(lazydb.LazyDB):
|
|||||||
spec, repo = self.get_spec_repo(name, repo)
|
spec, repo = self.get_spec_repo(name, repo)
|
||||||
return spec
|
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>'
|
resum = '<Summary xml:lang=.(%s|en).>.*?%s.*?</Summary>'
|
||||||
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
redesc = '<Description xml:lang=.(%s|en).>.*?%s.*?</Description>'
|
||||||
|
if not fields:
|
||||||
|
fields = {'name': True, 'summary': True, 'desc': True}
|
||||||
if not lang:
|
if not lang:
|
||||||
lang = pisi.pxml.autoxml.LocalText.get_lang()
|
lang = pisi.pxml.autoxml.LocalText.get_lang()
|
||||||
found = []
|
found = []
|
||||||
for name, xml in self.sdb.get_items_iter(repo):
|
for name, xml in self.sdb.get_items_iter(repo):
|
||||||
if terms == filter(lambda term: re.compile(term, re.I).search(name) or \
|
if terms == filter(lambda term: (fields['name'] and \
|
||||||
re.compile(resum % (lang, term), re.I).search(xml) or \
|
re.compile(term, re.I).search(name)) or \
|
||||||
re.compile(redesc % (lang, term), re.I).search(xml), terms):
|
(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)
|
found.append(name)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user