[equo] add new tool "equo query associate"

Given a file path (or multiple file paths) search applications able
to read mimetype belonging to it
This commit is contained in:
Fabio Erculiani
2010-05-18 20:10:02 +02:00
parent 96b4f23468
commit bdcd37772d
8 changed files with 59 additions and 16 deletions
+2
View File
@@ -196,6 +196,8 @@ help_opts = [
(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, 'associate', 2, _('associate given file paths to applications able to read them')),
(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')),
+16 -7
View File
@@ -22,7 +22,7 @@ from entropy.i18n import _
import entropy.tools
from entropy.db.exceptions import DatabaseError
from text_tools import print_table
from text_tools import print_table, get_file_mime
def query(options):
@@ -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 in ("match", "mimetype",)):
elif (opt == "--installed") and (first_opt in ("match", "mimetype", "associate",)):
match_installed = True
elif (opt == "--showrepo") and (first_opt == "match"):
show_repo = True
@@ -108,8 +108,10 @@ 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] in ("mimetype", "associate"):
associate = myopts[0] == "associate"
rc_status = search_mimetype(myopts[1:], installed = match_installed,
associate = associate)
elif myopts[0] == "required":
rc_status = search_required_libraries(myopts[1:])
@@ -1215,18 +1217,25 @@ def search_package(packages, Equo = None, get_results = False,
return rc_results
return 0
def search_mimetype(mimetypes, Equo = None, installed = False):
def search_mimetype(mimetypes, Equo = None, installed = False,
associate = False):
if Equo is None:
Equo = EquoInterface()
if not etpUi['quiet']:
print_info(darkred(" @@ ") + darkgreen("%s..." % (_("Searching mimetype"),) ),
back = True)
print_info(darkred(" @@ ") + darkgreen("%s..." % (
_("Searching mimetype"),) ), back = True)
found = False
for mimetype in mimetypes:
if associate:
# consider mimetype a file path
mimetype = get_file_mime(mimetype)
if mimetype is None:
continue
if not etpUi['quiet']:
print_info("%s: %s" % (blue(" # "), bold(mimetype),))
+16 -1
View File
@@ -324,4 +324,19 @@ def read_equo_release():
myrev = rev_f.readline().strip()
return myrev
return "0"
return "0"
def get_file_mime(file_path):
if not os.path.isfile(file_path):
return None
try:
import magic
except ImportError:
return None
handle = magic.open(magic.MAGIC_MIME)
handle.load()
mime = handle.file(file_path)
handle.close()
if mime:
mime = mime.split(";")[0]
return mime
-5
View File
@@ -2,11 +2,6 @@
0.99.50:
- sulfur: make use of provided_mime (and desktop_mime) metadata
import magic
handle = magic.open(magic.MAGIC_MIME)
handle.load()
handle.file("/path")
handle.close()
- move repository sync() code inside EntropyRepository? (makes sense)
- entropy.fetchers API docs
- entropy.server API docs
+12
View File
@@ -590,6 +590,18 @@ search inside installed packages
=back
=item B<associate>
associate given file paths to applications able to read them
=over
=item B<--installed>
search inside installed packages
=back
=item B<needed>
show runtime libraries needed by the provided atoms
+1 -1
View File
@@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "ACTIVATOR 1"
.TH ACTIVATOR 1 "2010-03-29" "perl v5.10.1" "Entropy"
.TH ACTIVATOR 1 "2010-03-25" "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
+11 -1
View File
@@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "EQUO 1"
.TH EQUO 1 "2010-05-09" "perl v5.10.1" "Entropy"
.TH EQUO 1 "2010-05-18" "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
@@ -591,6 +591,16 @@ search inside installed packages
.RE
.RS 4
.RE
.IP "\fBassociate\fR" 4
.IX Item "associate"
associate given file paths to applications able to read them
.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
+1 -1
View File
@@ -124,7 +124,7 @@
.\" ========================================================================
.\"
.IX Title "REAGENT 1"
.TH REAGENT 1 "2010-03-30" "perl v5.10.1" "Entropy"
.TH REAGENT 1 "2010-04-01" "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