如何使用 Python GIO 库根据卷类型卸载
How to unmount based on volume type using Python GIO library
我正在尝试模仿 shell 命令 gio mount
的行为,该命令卸载所有 gphoto2 相机
gio mount -s gphoto2
如何检测音量是否为gphoto2
?我尝试获取卷类型,但似乎没有保存它的变量,
from gi.repository import Gio, GObject
def main():
mo = Gio.MountOperation()
mo.set_anonymous(True)
vl = Gio.VolumeMonitor.get()
loop = GObject.MainLoop()
for v in vl.get_mounts():
print(dir(v))
print(v.get_name(), v.get_uuid(), v.g_type_instance, v.get_drive(),
v.get_volume(),
v.get_root(),
v.get_drive(),
v.get_sort_key(),
v.get_uuid())
获取挂载的根(https://developer.gnome.org/gio/stable/GMount.html#g-mount-get-root) and check its URI scheme (https://developer.gnome.org/gio/stable/GFile.html#g-file-has-uri-scheme)。如果scheme是gphoto2
,可以卸载
我正在尝试模仿 shell 命令 gio mount
的行为,该命令卸载所有 gphoto2 相机
gio mount -s gphoto2
如何检测音量是否为gphoto2
?我尝试获取卷类型,但似乎没有保存它的变量,
from gi.repository import Gio, GObject
def main():
mo = Gio.MountOperation()
mo.set_anonymous(True)
vl = Gio.VolumeMonitor.get()
loop = GObject.MainLoop()
for v in vl.get_mounts():
print(dir(v))
print(v.get_name(), v.get_uuid(), v.g_type_instance, v.get_drive(),
v.get_volume(),
v.get_root(),
v.get_drive(),
v.get_sort_key(),
v.get_uuid())
获取挂载的根(https://developer.gnome.org/gio/stable/GMount.html#g-mount-get-root) and check its URI scheme (https://developer.gnome.org/gio/stable/GFile.html#g-file-has-uri-scheme)。如果scheme是gphoto2
,可以卸载