8000 Use UDisks to find mounted filesystems on Linux by jwillikers · Pull Request #2683 · thonny/thonny · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use UDisks to find mounted filesystems on Linux #2683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packaging/requirements-regular-bundle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ paramiko==2.12.*
websockets==10.*
ptyprocess==0.7.*; sys_platform == "linux" or sys_platform == "darwin"
adafruit_board_toolkit==1.1.*; sys_platform == "win32" or sys_platform == "darwin"
dbus-next==0.2.*; sys_platform == "linux"


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def recursive_files(directory):
python_requires=">=3.8",
packages=find_packages(),
package_data={
"": ["VERSION", "defaults.ini", "res/*"]
"": ["VERSION", "defaults.ini", "res/*", "dbus/*"]
+ recursive_files("thonny/locale")
+ recursive_files("thonny/vendored_libs"),
"thonny.plugins.help": ["*.rst"],
Expand Down
17 changes: 17 additions & 0 deletions thonny/dbus/org.freedesktop.DBus.ObjectManager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.DBus.ObjectManager">
<method name="GetManagedObjects">
<arg type="a{oa{sa{sv}}}" name="object_paths_interfaces_and_properties" direction="out" />
</method>
<signal name="InterfacesAdded">
<arg type="o" name="object_path" />
<arg type="a{sa{sv}}" name="interfaces_and_properties" />
</signal>
<signal name="InterfacesRemoved">
<arg type="o" name="object_path" />
<arg type="as" name="interfaces" />
</signal>
</interface>
</node>
226 changes: 226 additions & 0 deletions thonny/dbus/org.freedesktop.UDisks2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.UDisks2.Manager">
<method name="CanFormat">
<arg type="s" name="type" direction="in" />
<arg type="(bs)" name="available" direction="out" />
</method>
<method name="CanResize">
<arg type="s" name="type" direction="in" />
<arg type="(bts)" name="available" direction="out" />
</method>
<method name="CanCheck">
<arg type="s" name="type" direction="in" />
<arg type="(bs)" name="available" direction="out" />
</method>
<method name="CanRepair">
<arg type="s" name="type" direction="in" />
<arg type="(bs)" name="available" direction="out" />
</method>
<method name="LoopSetup">
<arg type="h" name="fd" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
<arg type="o" name="resulting_device" direction="out" />
</method>
<method name="MDRaidCreate">
<arg type="ao" name="blocks" direction="in" />
<arg type="s" name="level" direction="in" />
<arg type="s" name="name" direction="in" />
<arg type="t" name="chunk" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
<arg type="o" name="resulting_array" direction="out" />
</method>
<method name="EnableModules">
<annotation name="org.freedesktop.DBus.Deprecated" value="true" />
<arg type="b" name="enable" direction="in" />
</method>
<method name="EnableModule">
<arg type="s" name="name" direction="in" />
<arg type="b" name="enable" direction="in" />
</method>
<method name="GetBlockDevices">
<arg type="a{sv}" name="options" direction="in" />
<arg type="ao" name="block_objects" direction="out" />
</method>
<method name="ResolveDevice">
<arg type="a{sv}" name="devspec" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
<arg type="ao" name="devices" direction="out" />
</method>
<property type="s" name="Version" access="read" />
<property type="as" name="SupportedFilesystems" access="read" />
<property type="as" name="SupportedEncryptionTypes" access="read" />
<property type="s" name="DefaultEncryptionType" access="read" />
</interface>
<interface name="org.freedesktop.UDisks2.Drive">
<method name="Eject">
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="SetConfiguration">
<arg type="a{sv}" name="value" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="PowerOff">
<arg type="a{sv}" name="options" direction="in" />
</method>
<property type="s" name="Vendor" access="read" />
<property type="s" name="Model" access="read" />
<property type="s" name="Revision" access="read" />
<property type="s" name="Serial" access="read" />
<property type="s" name="WWN" access="read" />
<property type="s" name="Id" access="read" />
<property type="a{sv}" name="Configuration" access="read" />
<property type="s" name="Media" access="read" />
<property type="as" name="MediaCompatibility" access="read" />
<property type="b" name="MediaRemovable" access="read" />
<property type="b" name="MediaAvailable" access="read" />
<property type="b" name="MediaChangeDetected" access="read" />
<property type="t" name="Size" access="read" />
<property type="t" name="TimeDetected" access="read" />
<property type="t" name="TimeMediaDetected" access="read" />
<property type="b" name="Optical" access="read" />
<property type="b" name="OpticalBlank" access="read" />
<property type="u" name="OpticalNumTracks" access="read" />
<property type="u" name="OpticalNumAudioTracks" access="read" />
<property type="u" name="OpticalNumDataTracks" access="read" />
<property type="u" name="OpticalNumSessions" access="read" />
<property type="i" name="RotationRate" access="read" />
<property type="s" name="ConnectionBus" access="read" />
<property type="s" name="Seat" access="read" />
<property type="b" name="Removable" access="read" />
<property type="b" name="Ejectable" access="read" />
<property type="s" name="SortKey" access="read" />
<property type="b" name="CanPowerOff" access="read" />
<property type="s" name="SiblingId" access="read" />
</interface>
<interface name="org.freedesktop.UDisks2.Filesystem">
<method name="SetLabel">
<arg type="s" name="label" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="Mount">
<arg type="a{sv}" name="options" direction="in" />
<arg type="s" name="mount_path" direction="out" />
</method>
<method name="Unmount">
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="Resize">
<arg type="t" name="size" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="Check">
<arg type="a{sv}" name="options" direction="in" />
<arg type="b" name="consistent" direction="out" />
</method>
<method name="Repair">
<arg type="a{sv}" name="options" direction="in" />
<arg type="b& EDBE quot; name="repaired" direction="out" />
</method>
<method name="TakeOwnership">
<arg type="a{sv}" name="options" direction="in" />
</method>
<property type="aay" name="MountPoints" access="read" />
<property type="t" name="Size" access="read" />
</interface>
<interface name="org.freedesktop.UDisks2.Partition">
<method name="SetType">
<arg type="s" name="type" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="SetName">
<arg type="s" name="name" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="SetFlags">
<arg type="t" name="flags" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="Resize">
<arg type="t" name="size" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="Delete">
<arg type="a{sv}" name="options" direction="in" />
</method>
<property type="u" name="Number" access="read" />
<property type="s" name="Type" access="read" />
<property type="t" name="Flags" access="read" />
<property type="t" name="Offset" access="read" />
<property type="t" name="Size" access="read" />
<property type="s" name="Name" access="read" />
<property type="s" name="UUID" access="read" />
<property type="o" name="Table" access="read" />
<property type="b" name="IsContainer" access="read" />
<property type="b" name="IsContained" access="read" />
</interface>
<interface name="org.freedesktop.UDisks2.Block">
<method name="AddConfigurationItem">
<arg type="(sa{sv})" name="item" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="RemoveConfigurationItem">
<arg type="(sa{sv})" name="item" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="UpdateConfigurationItem">
<arg type="(sa{sv})" name="old_item" direction="in" />
<arg type="(sa{sv})" name="new_item" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="GetSecretConfiguration">
<arg type="a{sv}" name="options" direction="in" />
<arg type="a(sa{sv})" name="configuration" direction="out" />
</method>
<method name="Format">
<arg type="s" name="type" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
</method>
<method name="OpenForBackup">
<arg type="a{sv}" name="options" direction="in" />
<arg type="h" name="fd" direction="out" />
</method>
<method name="OpenForRestore">
<arg type="a{sv}" name="options" direction="in" />
<arg type="h" name="fd" direction="out" />
</method>
<method name="OpenForBenchmark">
<arg type="a{sv}" name="options" direction="in" />
<arg type="h" name="fd" direction="out" />
</method>
<method name="OpenDevice">
<arg type="s" name="mode" direction="in" />
<arg type="a{sv}" name="options" direction="in" />
<arg type="h" name="fd" direction="out" />
</method>
<method name="Rescan">
<arg type="a{sv}" name="options" direction="in" />
</method>
<property type="ay" name="Device" access="read" />
<property type="ay" name="PreferredDevice" access="read" />
<property type="aay" name="Symlinks" access="read" />
<property type="t" name="DeviceNumber" access="read" />
<property type="s" name="Id" access="read" />
<property type="t" name="Size" access="read" />
<property type="b" name="ReadOnly" access="read" />
<property type="o" name="Drive" access="read" />
<property type="o" name="MDRaid" access="read" />
<property type="o" name="MDRaidMember" access="read" />
<property type="s" name="IdUsage" access="read" />
<property type="s" name="IdType" access="read" />
<property type="s" name="IdVersion" access="read" />
<property type="s" name="IdLabel" access="read" />
<property type="s" name="IdUUID" access="read" />
<property type="a(sa{sv})" name="Configuration" access="read" />
<property type="o" name="CryptoBackingDevice" access="read" />
<property type="b" name="HintPartitionable" access="read" />
<property type="b" name="HintSystem" access="read" />
<property type="b" name="HintIgnore" access="read" />
<property type="b" name="HintAuto" access="read" />
1E0A <property type="s" name="HintName" access="read" />
<property type="s" name="HintIconName" access="read" />
<property type="s" name="HintSymbolicIconName" access="read" />
<property type="as" name="UserspaceMountOptions" access="read" />
</interface>
</node>
17 changes: 16 additions & 1 deletion thonny/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,23 @@ def list_volumes(skip_letters=set()) -> Sequence[str]:
return volumes
finally:
ctypes.windll.kernel32.SetErrorMode(old_mode) # @UndefinedVariable
if sys.platform == "linux":
from dbus_next.errors import DBusError

from thonny.udisks import list_volumes_sync

mount_points = []
try:
mount_points = list_volumes_sync()
except DBusError as error:
# Fallback to using the 'mount' command on Linux if the Udisks D-Bus service is unavailable.
if "org.freedesktop.DBus.Error.ServiceUnknown" not in error.text:
raise
mount_output = subprocess.check_output("mount").splitlines()
mount_points = [x.split()[2].decode("utf-8") for x in mount_output]
return mount_points
else:
# 'posix' means we're on Linux or OSX (Mac).
# 'posix' means we're on *BSD or OSX (Mac).
# Call the unix "mount" command to list the mounted volumes.
mount_output = subprocess.check_output("mount").splitlines()
return [x.split()[2].decode("utf-8") for x in mount_output]
Expand Down
Loading
0