diff --git a/client/equo.py b/client/equo.py index 045ea047a..23b93f1e7 100644 --- a/client/equo.py +++ b/client/equo.py @@ -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')), diff --git a/client/text_query.py b/client/text_query.py index 26f23db52..342e9b466 100644 --- a/client/text_query.py +++ b/client/text_query.py @@ -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),)) diff --git a/client/text_tools.py b/client/text_tools.py index 0af4967e4..d4c1a5c3a 100644 --- a/client/text_tools.py +++ b/client/text_tools.py @@ -324,4 +324,19 @@ def read_equo_release(): myrev = rev_f.readline().strip() return myrev - return "0" \ No newline at end of file + 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 diff --git a/docs/TODO b/docs/TODO index 64fb1a844..49b84f63d 100644 --- a/docs/TODO +++ b/docs/TODO @@ -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 diff --git a/docs/man/equo.pod b/docs/man/equo.pod index 82a8e5704..bae616127 100644 --- a/docs/man/equo.pod +++ b/docs/man/equo.pod @@ -590,6 +590,18 @@ search inside installed packages =back +=item B + +associate given file paths to applications able to read them + +=over + +=item B<--installed> + +search inside installed packages + +=back + =item B show runtime libraries needed by the provided atoms diff --git a/docs/man/man1/activator.1 b/docs/man/man1/activator.1 index 18baa4d49..13eee5238 100644 --- a/docs/man/man1/activator.1 +++ b/docs/man/man1/activator.1 @@ -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 diff --git a/docs/man/man1/equo.1 b/docs/man/man1/equo.1 index 625930a0b..1689e9011 100644 --- a/docs/man/man1/equo.1 +++ b/docs/man/man1/equo.1 @@ -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 diff --git a/docs/man/man1/reagent.1 b/docs/man/man1/reagent.1 index 1daab760d..61964ebab 100644 --- a/docs/man/man1/reagent.1 +++ b/docs/man/man1/reagent.1 @@ -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