Python:获取与文件关联的应用程序列表(Linux)
我正在用 Python 制作一个应用程序,我需要向用户提供“打开方式”菜单。目前我正在解析 /usr/share/applications/mimeinfo.cashe
和 ~/.local/share/applications/mimeapps.list
但结果很差。 Nautilus 在“打开方式”菜单中有更多条目。
您知道获取与文件关联的应用程序列表的更好方法吗?
编辑:
使用 gnomevfs 模块有一种更简单的方法。
mime_type = gnomevfs.get_mime_type(filename)
application_list = gnomevfs.mime_get_all_applications(mime_type)
在返回的列表中,您可以获得应用程序名称、图标名称、配置文件和许多其他内容。
Am making an application in Python and I need to provide "Open with" menu to user. Currently I am parsing /usr/share/applications/mimeinfo.cashe
and ~/.local/share/applications/mimeapps.list
but with very poor results. Nautilus has more entries in "Open with" menu.
Do you know a better way for getting list of applications associated with file?
Edit:
There is a simpler way using gnomevfs
module.
mime_type = gnomevfs.get_mime_type(filename)
application_list = gnomevfs.mime_get_all_applications(mime_type)
In returned list you get application name, icon name, config file and many other stuff.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了一个更优雅的解决方案。在
gnomevfs
模块中,有一个名为mime_get_all_applications
的函数,它返回关联应用程序的正确列表。更多信息可以在此处找到。
编辑:
自撰写此答案以来,GnomeVFS 已被标记为已弃用。 GIO 现在确实通过
app_info_get_all
和app_info_get_for_type
等方法提供了此功能。I've found a bit more elegant solution. In
gnomevfs
module there is function namedmime_get_all_applications
which returns proper list of associated applications.More information can be found here.
Edit:
Since the time this answer was written, GnomeVFS was marked as deprecated. GIO does provide this functionality now with methods like
app_info_get_all
andapp_info_get_for_type
.GNOME 将其应用程序列表存储在这两个文件中:
(链接至来源)
GNOME stores its application lists in those two files:
(link to source)