使用 Python 禁用 GNOME 自动挂载

发布于 2024-07-24 22:41:23 字数 65 浏览 5 评论 0原文

我需要阻止 GNOME/Nautilus 自动安装系统中出现的新设备和分区。 我怎样才能在Python中完成这个?

I need to stop GNOME/Nautilus from automagically mounting new devices and partitions as they appear to the system. How can I accomplish this in python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2024-07-31 22:41:23

为什么要用 Python 来做呢? 您可以只使用命令行,如下所示:

gconftool-2 --type bool --set /apps/nautilus/preferences/media_automount false

如果您确实需要在Python中使用它,那么您可以使用 子流程模块

import subprocess

def setAutomount(value):
    """
    @type value: boolean
    """
    cmd = ['gconftool-2', '--type', 'bool', '--set', 
            '/apps/nautilus/preferences/media_automount']
    cmd.append(str(value).lower())
    subprocess.check_call(cmd)

setAutomount(False)

但我真的不确定这里是否有必要。

Why would do it in Python? You can just use the commandline, as in:

gconftool-2 --type bool --set /apps/nautilus/preferences/media_automount false

If you really need it to be in Python, then you can use the subprocess module:

import subprocess

def setAutomount(value):
    """
    @type value: boolean
    """
    cmd = ['gconftool-2', '--type', 'bool', '--set', 
            '/apps/nautilus/preferences/media_automount']
    cmd.append(str(value).lower())
    subprocess.check_call(cmd)

setAutomount(False)

But I'm really not sure that it's necessary here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文