[entropy.client/equo] add "equo query mimetype" support

User can now search for packages providing a specific mimetype,
which means, telling the user what application can be used to
open his/her files.
Add two now entropy.client.interfaces.Client methods:
  - list search_installed_mimetype(string mimetype)
  - list search_available_mimetype(string mimetype)
This commit is contained in:
Fabio Erculiani
2010-05-02 23:49:44 +02:00
parent 85ba650101
commit c9790ce36a
5 changed files with 101 additions and 4 deletions

View File

@@ -192,6 +192,8 @@ help_opts = [
(2, 'list', 2, _('list packages based on the chosen parameter below')),
(3, 'installed', 2, _('list installed packages')),
(3, 'available [repos]', 1, _('list available packages')),
(2, 'mimetype', 2, _('search packages able to handle given mimetypes')),
(3, '--installed', 2, _('search among installed packages')),
(2, 'needed', 2, _('show runtime libraries needed by the provided atoms')),
(2, 'orphans', 1, _('search files that do not belong to any package')),
(2, 'removal', 1, _('show the removal tree for the specified atoms')),

View File

@@ -56,7 +56,7 @@ def query(options):
multi_match = True
elif (opt == "--multirepo") and (first_opt == "match"):
multi_repo = True
elif (opt == "--installed") and (first_opt == "match"):
elif (opt == "--installed") and (first_opt in ("match", "mimetype",)):
match_installed = True
elif (opt == "--showrepo") and (first_opt == "match"):
show_repo = True
@@ -108,6 +108,9 @@ def query(options):
elif myopts[0] == "needed":
rc_status = search_needed_libraries(myopts[1:])
elif myopts[0] == "mimetype":
rc_status = search_mimetype(myopts[1:], installed = match_installed)
elif myopts[0] == "required":
rc_status = search_required_libraries(myopts[1:])
@@ -1211,6 +1214,47 @@ def search_package(packages, Equo = None, get_results = False,
return rc_results
return 0
def search_mimetype(mimetypes, Equo = None, installed = False):
if Equo is None:
Equo = EquoInterface()
if not etpUi['quiet']:
print_info(darkred(" @@ ") + darkgreen("%s..." % (_("Searching mimetype"),) ),
back = True)
found = False
for mimetype in mimetypes:
if not etpUi['quiet']:
print_info("%s: %s" % (blue(" # "), bold(mimetype),))
if installed:
matches = [(x, etpConst['clientdbid']) for x in \
Equo.search_installed_mimetype(mimetype)]
else:
matches = Equo.search_available_mimetype(mimetype)
if matches:
found = True
for match in matches:
dbconn = Equo.open_repository(match[1])
print_package_info(match[0], dbconn, Equo = Equo,
extended = etpUi['verbose'])
if not etpUi['quiet']:
toc = []
toc.append(("%s:" % (blue(_("Keyword")),), purple(mimetype)))
toc.append(("%s:" % (blue(_("Found")),), "%s %s" % (
len(matches), brown(_("entries")),)))
print_table(toc)
if not etpUi['quiet'] and not found:
print_info(darkred(" @@ ") + darkgreen("%s." % (_("No matches"),) ))
return 0
def match_package(packages, multiMatch = False, multiRepo = False,
showRepo = False, showDesc = False, Equo = None, get_results = False,
installed = False):

View File

@@ -570,6 +570,18 @@ list installed packages
=back
=item B<mimetype>
search packages able to handle given mimetypes
=over
=item B<--installed>
search inside installed packages
=back
=item B<needed>
show runtime libraries needed by the provided atoms

View File

@@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "EQUO 1"
.TH EQUO 1 "2010-04-16" "perl v5.10.1" "Entropy"
.TH EQUO 1 "2010-05-02" "perl v5.10.1" "Entropy"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
@@ -575,6 +575,16 @@ list installed packages
.RE
.RS 4
.RE
.IP "\fBmimetype\fR" 4
.IX Item "mimetype"
search packages able to handle given mimetypes
.RS 4
.IP "\fB\-\-installed\fR" 4
.IX Item "--installed"
search inside installed packages
.RE
.RS 4
.RE
.IP "\fBneeded\fR" 4
.IX Item "needed"
show runtime libraries needed by the provided atoms
@@ -1160,6 +1170,6 @@ Fabio Erculiani <lxnay@sabayon.org>
.SH "POD ERRORS"
.IX Header "POD ERRORS"
Hey! \fBThe above document had some coding errors, which are explained below:\fR
.IP "Around line 1320:" 4
.IX Item "Around line 1320:"
.IP "Around line 1332:" 4
.IX Item "Around line 1332:"
You forgot a '=back' before '=head1'

View File

@@ -1731,3 +1731,32 @@ class MatchMixin:
except OSError:
shutil.copy2(tmp_path, mask_file)
os.remove(tmp_path)
def search_installed_mimetype(self, mimetype):
"""
Given a mimetype, return list of installed package identifiers
belonging to packages that can handle it.
@param mimetype: mimetype string
@type mimetype: string
@return: list of installed package identifiers
@rtype: list
"""
return self._installed_repository.searchProvidedMime(mimetype)
def search_available_mimetype(self, mimetype):
"""
Given a mimetype, return list of available package matches
belonging to packages that can handle it.
@param mimetype: mimetype string
@type mimetype: string
@return: list of available package matches
@rtype: list
"""
packages = []
for repo in self._enabled_repos:
repo_db = self.open_repository(repo)
packages += [(x, repo) for x in \
repo_db.searchProvidedMime(mimetype)]
return packages