code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def is_utf8(bs):
"""Check if the given bytes string is utf-8 decodable."""
try:
bs.decode('utf-8')
return True
except UnicodeDecodeError:
return False | Check if the given bytes string is utf-8 decodable. | is_utf8 | python | coldfix/udiskie | udiskie/common.py | https://github.com/coldfix/udiskie/blob/master/udiskie/common.py | MIT |
def __init__(self, match):
"""Construct from dict of device matching attributes."""
self._log = logging.getLogger(__name__)
self._match = match = match.copy()
self._values = {}
# mount options:
if 'options' in match:
options = match.pop('options')
... | Construct from dict of device matching attributes. | __init__ | python | coldfix/udiskie | udiskie/config.py | https://github.com/coldfix/udiskie/blob/master/udiskie/config.py | MIT |
def match(self, device):
"""Check if the device object matches this filter."""
return all(match_value(getattr(device, k), v)
for k, v in self._match.items()) | Check if the device object matches this filter. | match | python | coldfix/udiskie | udiskie/config.py | https://github.com/coldfix/udiskie/blob/master/udiskie/config.py | MIT |
def value(self, kind, device):
"""
Get the value for the device object associated with this filter.
If :meth:`match` is False for the device, the return value of this
method is undefined.
"""
self._log.debug(_('{0} matched {1}',
device.device_fi... |
Get the value for the device object associated with this filter.
If :meth:`match` is False for the device, the return value of this
method is undefined.
| value | python | coldfix/udiskie | udiskie/config.py | https://github.com/coldfix/udiskie/blob/master/udiskie/config.py | MIT |
def match_config(filters, device, kind, default):
"""
Matches devices against multiple :class:`DeviceFilter`s.
:param list filters: device filters
:param Device device: device to be mounted
:param str kind: value kind
:param default: default value
:returns: value of the first matching filte... |
Matches devices against multiple :class:`DeviceFilter`s.
:param list filters: device filters
:param Device device: device to be mounted
:param str kind: value kind
:param default: default value
:returns: value of the first matching filter
| match_config | python | coldfix/udiskie | udiskie/config.py | https://github.com/coldfix/udiskie/blob/master/udiskie/config.py | MIT |
def default_pathes(cls):
"""Return the default config file paths as a list."""
config_home = (
os.environ.get('XDG_CONFIG_HOME') or
os.path.expanduser('~/.config'))
return [os.path.join(config_home, 'udiskie', 'config.yml'),
os.path.join(config_home, 'udis... | Return the default config file paths as a list. | default_pathes | python | coldfix/udiskie | udiskie/config.py | https://github.com/coldfix/udiskie/blob/master/udiskie/config.py | MIT |
def from_file(cls, path=None):
"""
Read YAML config file. Returns Config object.
:raises IOError: if the path does not exist
"""
# None => use default
if path is None:
for path in cls.default_pathes():
try:
return cls.from_... |
Read YAML config file. Returns Config object.
:raises IOError: if the path does not exist
| from_file | python | coldfix/udiskie | udiskie/config.py | https://github.com/coldfix/udiskie/blob/master/udiskie/config.py | MIT |
async def call(proxy, method_name, signature, args, flags=0, timeout_msec=-1):
"""
Asynchronously call the specified method on a DBus proxy object.
:param Gio.DBusProxy proxy:
:param str method_name:
:param str signature:
:param tuple args:
:param int flags:
:param int timeout_msec:
... |
Asynchronously call the specified method on a DBus proxy object.
:param Gio.DBusProxy proxy:
:param str method_name:
:param str signature:
:param tuple args:
:param int flags:
:param int timeout_msec:
| call | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
async def call_with_fd_list(proxy, method_name, signature, args, fds,
flags=0, timeout_msec=-1):
"""
Asynchronously call the specified method on a DBus proxy object.
:param Gio.DBusProxy proxy:
:param str method_name:
:param str signature:
:param tuple args:
:par... |
Asynchronously call the specified method on a DBus proxy object.
:param Gio.DBusProxy proxy:
:param str method_name:
:param str signature:
:param tuple args:
:param list fds:
:param int flags:
:param int timeout_msec:
| call_with_fd_list | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def __init__(self, proxy):
"""
Initialize property and method attribute accessors for the interface.
:param Gio.DBusProxy proxy: accessed object
"""
self._proxy = proxy
self.object_path = proxy.get_object_path() |
Initialize property and method attribute accessors for the interface.
:param Gio.DBusProxy proxy: accessed object
| __init__ | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def object(self):
"""Get an ObjectProxy instanec for the underlying object."""
proxy = self._proxy
return ObjectProxy(proxy.get_connection(),
proxy.get_name(),
proxy.get_object_path()) | Get an ObjectProxy instanec for the underlying object. | object | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def connect(self, event, handler):
"""Connect to a DBus signal, returns subscription id (int)."""
interface = self._proxy.get_interface_name()
return self.object.connect(interface, event, handler) | Connect to a DBus signal, returns subscription id (int). | connect | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def __init__(self, connection, bus_name, object_path):
"""
Initialize member variables.
:ivar Gio.DBusConnection connection:
:ivar str bus_name:
:ivar str object_path:
This performs no IO at all.
"""
self.connection = connection
self.bus_name = b... |
Initialize member variables.
:ivar Gio.DBusConnection connection:
:ivar str bus_name:
:ivar str object_path:
This performs no IO at all.
| __init__ | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def _get_interface(self, name):
"""Get a Future(Gio.DBusProxy) for the specified interface."""
return proxy_new(
self.connection,
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
info=None,
name=self.bus_na... | Get a Future(Gio.DBusProxy) for the specified interface. | _get_interface | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
async def get_interface(self, name):
"""Get an InterfaceProxy for the specified interface."""
proxy = await self._get_interface(name)
return InterfaceProxy(proxy) | Get an InterfaceProxy for the specified interface. | get_interface | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def connect(self, interface, event, handler):
"""Connect to a DBus signal. Returns subscription id (int)."""
object_path = self.object_path
return self.bus.connect(interface, event, object_path, handler) | Connect to a DBus signal. Returns subscription id (int). | connect | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def __init__(self, connection, bus_name):
"""
Initialize member variables.
:param Gio.DBusConnection connection:
:param str bus_name:
This performs IO at all.
"""
self.connection = connection
self.bus_name = bus_name |
Initialize member variables.
:param Gio.DBusConnection connection:
:param str bus_name:
This performs IO at all.
| __init__ | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def connect(self, interface, event, object_path, handler):
"""
Connect to a DBus signal. If ``object_path`` is None, subscribe for
all objects and invoke the callback with the object_path as its first
argument.
"""
if object_path:
def callback(connection, send... |
Connect to a DBus signal. If ``object_path`` is None, subscribe for
all objects and invoke the callback with the object_path as its first
argument.
| connect | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
async def proxy_new(connection, flags, info, name, object_path, interface_name):
"""Asynchronously call the specified method on a DBus proxy object."""
future = Future()
cancellable = None
Gio.DBusProxy.new(
connection,
flags,
info,
name,
object_path,
inte... | Asynchronously call the specified method on a DBus proxy object. | proxy_new | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
async def connect_service(bus_name, object_path, interface):
"""Connect to the service object on DBus, return InterfaceProxy."""
proxy = await proxy_new_for_bus(
Gio.BusType.SYSTEM,
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
info=None,
... | Connect to the service object on DBus, return InterfaceProxy. | connect_service | python | coldfix/udiskie | udiskie/dbus.py | https://github.com/coldfix/udiskie/blob/master/udiskie/dbus.py | MIT |
def require_Gtk(min_version=2):
"""
Make sure Gtk is properly initialized.
:raises RuntimeError: if Gtk can not be properly initialized
"""
if not (_in_X or _in_Wayland):
raise RuntimeError('Not in X or Wayland session.')
if _has_Gtk < min_version:
raise RuntimeError('Module gi.... |
Make sure Gtk is properly initialized.
:raises RuntimeError: if Gtk can not be properly initialized
| require_Gtk | python | coldfix/udiskie | udiskie/depend.py | https://github.com/coldfix/udiskie/blob/master/udiskie/depend.py | MIT |
def _(text, *args, **kwargs):
"""Translate and then and format the text with ``str.format``."""
msg = _t.gettext(text)
if args or kwargs:
return msg.format(*args, **kwargs)
else:
return msg | Translate and then and format the text with ``str.format``. | _ | python | coldfix/udiskie | udiskie/locale.py | https://github.com/coldfix/udiskie/blob/master/udiskie/locale.py | MIT |
def _is_parent_of(parent, child):
"""Check whether the first device is the parent of the second device."""
if child.is_partition:
return child.partition_slave == parent
if child.is_toplevel:
return child.drive == parent and child != parent
return False | Check whether the first device is the parent of the second device. | _is_parent_of | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def __init__(self, udisks, config=None, prompt=None, browser=None,
terminal=None, cache=None, cache_hint=False):
"""
Initialize mounter with the given defaults.
:param udisks: udisks service object. May be a Sniffer or a Daemon.
:param list config: list of :class:`Devic... |
Initialize mounter with the given defaults.
:param udisks: udisks service object. May be a Sniffer or a Daemon.
:param list config: list of :class:`DeviceFilter`
:param callable prompt: retrieve passwords for devices
:param callable browser: open devices
:param callable... | __init__ | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def browse(self, device):
"""
Launch file manager on the mount path of the specified device.
:param device: device object, block device path or mount path
:returns: whether the program was successfully launched.
"""
device = self._find_device(device)
if not... |
Launch file manager on the mount path of the specified device.
:param device: device object, block device path or mount path
:returns: whether the program was successfully launched.
| browse | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def terminal(self, device):
"""
Launch terminal on the mount path of the specified device.
:param device: device object, block device path or mount path
:returns: whether the program was successfully launched.
"""
device = self._find_device(device)
if not d... |
Launch terminal on the mount path of the specified device.
:param device: device object, block device path or mount path
:returns: whether the program was successfully launched.
| terminal | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def mount(self, device):
"""
Mount the device if not already mounted.
:param device: device object, block device path or mount path
:returns: whether the device is mounted.
"""
device = self._find_device(device)
if not self.is_handleable(device) or not devi... |
Mount the device if not already mounted.
:param device: device object, block device path or mount path
:returns: whether the device is mounted.
| mount | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def unmount(self, device):
"""
Unmount a Device if mounted.
:param device: device object, block device path or mount path
:returns: whether the device is unmounted
"""
device = self._find_device(device)
if not self.is_handleable(device) or not device.is_fil... |
Unmount a Device if mounted.
:param device: device object, block device path or mount path
:returns: whether the device is unmounted
| unmount | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def unlock(self, device):
"""
Unlock the device if not already unlocked.
:param device: device object, block device path or mount path
:returns: whether the device is unlocked
"""
device = self._find_device(device)
if not self.is_handleable(device) or not d... |
Unlock the device if not already unlocked.
:param device: device object, block device path or mount path
:returns: whether the device is unlocked
| unlock | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def lock(self, device):
"""
Lock device if unlocked.
:param device: device object, block device path or mount path
:returns: whether the device is locked
"""
device = self._find_device(device)
if not self.is_handleable(device) or not device.is_crypto:
... |
Lock device if unlocked.
:param device: device object, block device path or mount path
:returns: whether the device is locked
| lock | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def add(self, device, recursive=None):
"""
Mount or unlock the device depending on its type.
:param device: device object, block device path or mount path
:param bool recursive: recursively mount and unlock child devices
:returns: whether all attempted operations succeeded... |
Mount or unlock the device depending on its type.
:param device: device object, block device path or mount path
:param bool recursive: recursively mount and unlock child devices
:returns: whether all attempted operations succeeded
| add | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def auto_add(self, device, recursive=None, automount=True):
"""
Automatically attempt to mount or unlock a device, but be quiet if the
device is not supported.
:param device: device object, block device path or mount path
:param bool recursive: recursively mount and unlock... |
Automatically attempt to mount or unlock a device, but be quiet if the
device is not supported.
:param device: device object, block device path or mount path
:param bool recursive: recursively mount and unlock child devices
:returns: whether all attempted operations succeeded
... | auto_add | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def remove(self, device, force=False, detach=False, eject=False,
lock=False):
"""
Unmount or lock the device depending on device type.
:param device: device object, block device path or mount path
:param bool force: recursively remove all child devices
... |
Unmount or lock the device depending on device type.
:param device: device object, block device path or mount path
:param bool force: recursively remove all child devices
:param bool detach: detach the root drive
:param bool eject: remove media from the root drive
:para... | remove | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def eject(self, device, force=False):
"""
Eject a device after unmounting all its mounted filesystems.
:param device: device object, block device path or mount path
:param bool force: remove child devices before trying to eject
:returns: whether the operation succeeded
... |
Eject a device after unmounting all its mounted filesystems.
:param device: device object, block device path or mount path
:param bool force: remove child devices before trying to eject
:returns: whether the operation succeeded
| eject | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def detach(self, device, force=False):
"""
Detach a device after unmounting all its mounted filesystems.
:param device: device object, block device path or mount path
:param bool force: remove child devices before trying to detach
:returns: whether the operation succeeded
... |
Detach a device after unmounting all its mounted filesystems.
:param device: device object, block device path or mount path
:param bool force: remove child devices before trying to detach
:returns: whether the operation succeeded
| detach | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def add_all(self, recursive=False):
"""
Add all handleable devices that available at start.
:param bool recursive: recursively mount and unlock child devices
:returns: whether all attempted operations succeeded
"""
tasks = [self.auto_add(device, recursive=recursive... |
Add all handleable devices that available at start.
:param bool recursive: recursively mount and unlock child devices
:returns: whether all attempted operations succeeded
| add_all | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def remove_all(self, detach=False, eject=False, lock=False):
"""
Remove all filesystems handleable by udiskie.
:param bool detach: detach the root drive
:param bool eject: remove media from the root drive
:param bool lock: lock the associated LUKS cleartext slave
:... |
Remove all filesystems handleable by udiskie.
:param bool detach: detach the root drive
:param bool eject: remove media from the root drive
:param bool lock: lock the associated LUKS cleartext slave
:returns: whether all attempted operations succeeded
| remove_all | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def losetup(self, image, read_only=None, offset=None, size=None,
no_part_scan=None):
"""
Setup a loop device.
:param str image: path of the image file
:param bool read_only:
:param int offset:
:param int size:
:param bool no_part_scan:... |
Setup a loop device.
:param str image: path of the image file
:param bool read_only:
:param int offset:
:param int size:
:param bool no_part_scan:
:returns: the device object for the loop device
| losetup | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
async def delete(self, device, remove=True):
"""
Detach the loop device.
:param device: device object, block device path or mount path
:param bool remove: whether to unmount the partition etc.
:returns: whether the loop device is deleted
"""
device = self._find_d... |
Detach the loop device.
:param device: device object, block device path or mount path
:param bool remove: whether to unmount the partition etc.
:returns: whether the loop device is deleted
| delete | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def is_handleable(self, device):
# TODO: handle paths in first argument
"""
Check whether this device should be handled by udiskie.
:param device: device object, block device path or mount path
:returns: handleability
Currently this just means that the device is removab... |
Check whether this device should be handled by udiskie.
:param device: device object, block device path or mount path
:returns: handleability
Currently this just means that the device is removable and holds a
filesystem or the device is a LUKS encrypted volume.
| is_handleable | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def is_addable(self, device, automount=True):
"""Check if device can be added with ``auto_add``."""
if not self.is_automount(device, automount):
return False
if device.is_filesystem:
return not device.is_mounted
if device.is_crypto:
return self._prompt... | Check if device can be added with ``auto_add``. | is_addable | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def is_removable(self, device):
"""Check if device can be removed with ``auto_remove``."""
if not self.is_handleable(device):
return False
if device.is_filesystem:
return device.is_mounted
if device.is_crypto:
return device.is_unlocked
if devic... | Check if device can be removed with ``auto_remove``. | is_removable | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def get_all_handleable(self):
"""Get list of all known handleable devices."""
nodes = self.get_device_tree()
return [node.device
for node in sorted(nodes.values(), key=DevNode._sort_key)
if not node.ignored and node.device] | Get list of all known handleable devices. | get_all_handleable | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def get_all_handleable_roots(self):
"""
Get list of all handleable devices, return only those that represent
root nodes within the filtered device tree.
"""
nodes = self.get_device_tree()
return [node.device
for node in sorted(nodes.values(), key=DevNode._... |
Get list of all handleable devices, return only those that represent
root nodes within the filtered device tree.
| get_all_handleable_roots | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def get_all_handleable_leaves(self):
"""
Get list of all handleable devices, return only those that represent
leaf nodes within the filtered device tree.
"""
nodes = self.get_device_tree()
return [node.device
for node in sorted(nodes.values(), key=DevNode.... |
Get list of all handleable devices, return only those that represent
leaf nodes within the filtered device tree.
| get_all_handleable_leaves | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def detect(self, root_device='/'):
"""
Detect all currently known devices.
:param str root_device: object path of root device to return
:returns: root node of device hierarchy
"""
root = Device(None, [], None, "", [])
device_nodes = dict(map(self._device_node,
... |
Detect all currently known devices.
:param str root_device: object path of root device to return
:returns: root node of device hierarchy
| detect | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def _get_device_methods(self, device):
"""Return an iterable over all available methods the device has."""
if device.is_filesystem:
if device.is_mounted:
if self._mounter._browser:
yield 'browse'
if self._mounter._terminal:
... | Return an iterable over all available methods the device has. | _get_device_methods | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def _device_node(self, device):
"""Create an empty menu node for the specified device."""
label = device.ui_label
dev_label = device.ui_device_label
# determine available methods
methods = [Action(method, device,
self._labels[method].format(label, dev_la... | Create an empty menu node for the specified device. | _device_node | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def prune_empty_node(node, seen):
"""
Recursively remove empty branches and return whether this makes the node
itself empty.
The ``seen`` parameter is used to avoid infinite recursion due to cycles
(you never know).
"""
if node.methods:
return False
if id(node) in seen:
... |
Recursively remove empty branches and return whether this makes the node
itself empty.
The ``seen`` parameter is used to avoid infinite recursion due to cycles
(you never know).
| prune_empty_node | python | coldfix/udiskie | udiskie/mount.py | https://github.com/coldfix/udiskie/blob/master/udiskie/mount.py | MIT |
def __init__(self, notify, mounter, timeout=None, aconfig=None):
"""
Initialize notifier and connect to service.
:param notify: notification service module (gi.repository.Notify)
:param mounter: Mounter object
:param dict timeout: dictionary with timeouts for notifications
... |
Initialize notifier and connect to service.
:param notify: notification service module (gi.repository.Notify)
:param mounter: Mounter object
:param dict timeout: dictionary with timeouts for notifications
| __init__ | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def device_mounted(self, device):
"""Show mount notification for specified device object."""
if not self._mounter.is_handleable(device):
return
browse_action = (device, 'browse', _('Browse directory'),
self._mounter.browse, device)
terminal_action = (... | Show mount notification for specified device object. | device_mounted | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def device_unmounted(self, device):
"""Show unmount notification for specified device object."""
if not self._mounter.is_handleable(device):
return
self._show_notification(
'device_unmounted',
_('Device unmounted'),
_('{0.ui_label} unmounted', devi... | Show unmount notification for specified device object. | device_unmounted | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def device_locked(self, device):
"""Show lock notification for specified device object."""
if not self._mounter.is_handleable(device):
return
self._show_notification(
'device_locked',
_('Device locked'),
_('{0.device_presentation} locked', device),... | Show lock notification for specified device object. | device_locked | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def device_unlocked(self, device):
"""Show unlock notification for specified device object."""
if not self._mounter.is_handleable(device):
return
self._show_notification(
'device_unlocked',
_('Device unlocked'),
_('{0.device_presentation} unlocked'... | Show unlock notification for specified device object. | device_unlocked | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def device_added(self, device):
"""Show discovery notification for specified device object."""
if not self._mounter.is_handleable(device):
return
if self._has_actions('device_added'):
# wait for partitions etc to be reported to udiskie, otherwise we
# can't di... | Show discovery notification for specified device object. | device_added | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def device_removed(self, device):
"""Show removal notification for specified device object."""
if not self._mounter.is_handleable(device):
return
device_file = device.device_presentation
if (device.is_drive or device.is_toplevel) and device_file:
self._show_notifi... | Show removal notification for specified device object. | device_removed | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def job_failed(self, device, action, message):
"""Show 'Job failed' notification with 'Retry' button."""
if not self._mounter.is_handleable(device):
return
device_file = device.device_presentation or device.object_path
if message:
text = _('failed to {0} {1}:\n{2}... | Show 'Job failed' notification with 'Retry' button. | job_failed | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def _show_notification(self,
event, summary, message, icon,
*actions):
"""
Show a notification.
:param str event: event name
:param str summary: notification title
:param str message: notification body
:param str icon... |
Show a notification.
:param str event: event name
:param str summary: notification title
:param str message: notification body
:param str icon: icon name
:param actions: each item is a tuple with parameters for _add_action
| _show_notification | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def _add_action(self, notification, device, action, label, callback, *args):
"""
Show an action button button in mount notifications.
Note, this only works with some libnotify services.
"""
action = action + ':' + device.device_file
on_action_click = run_bg(lambda *_: ca... |
Show an action button button in mount notifications.
Note, this only works with some libnotify services.
| _add_action | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def _action_enabled(self, event, action):
"""Check if an action for a notification is enabled."""
event_actions = self._aconfig.get(event)
if event_actions is None:
return True
if event_actions is False:
return False
return action in event_actions | Check if an action for a notification is enabled. | _action_enabled | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
def _has_actions(self, event):
"""Check if a notification type has any enabled actions."""
event_actions = self._aconfig.get(event)
return event_actions is None or bool(event_actions) | Check if a notification type has any enabled actions. | _has_actions | python | coldfix/udiskie | udiskie/notify.py | https://github.com/coldfix/udiskie/blob/master/udiskie/notify.py | MIT |
async def password_dialog(key, title, message, options):
"""
Show a Gtk password dialog.
:returns: the password or ``None`` if the user aborted the operation
:raises RuntimeError: if Gtk can not be properly initialized
"""
with PasswordDialog.create(key, title, message, options) as dialog:
... |
Show a Gtk password dialog.
:returns: the password or ``None`` if the user aborted the operation
:raises RuntimeError: if Gtk can not be properly initialized
| password_dialog | python | coldfix/udiskie | udiskie/prompt.py | https://github.com/coldfix/udiskie/blob/master/udiskie/prompt.py | MIT |
def get_password_gui(device, options):
"""Get the password to unlock a device from GUI."""
text = _('Enter password for {0.device_presentation}: ', device)
try:
return password_dialog(device.id_uuid, 'udiskie', text, options)
except RuntimeError:
return None | Get the password to unlock a device from GUI. | get_password_gui | python | coldfix/udiskie | udiskie/prompt.py | https://github.com/coldfix/udiskie/blob/master/udiskie/prompt.py | MIT |
async def get_password_tty(device, options):
"""Get the password to unlock a device from terminal."""
# TODO: make this a TRUE async
text = _('Enter password for {0.device_presentation}: ', device)
try:
return PasswordResult(getpass.getpass(text))
except EOFError:
print("")
r... | Get the password to unlock a device from terminal. | get_password_tty | python | coldfix/udiskie | udiskie/prompt.py | https://github.com/coldfix/udiskie/blob/master/udiskie/prompt.py | MIT |
def __init__(self, argv, capture=False, **extra):
"""Create the launcher object from the command line template."""
if isinstance(argv, str):
self.argv = shlex.split(argv)
else:
self.argv = argv
self.capture = capture
self.extra = extra.copy()
# obt... | Create the launcher object from the command line template. | __init__ | python | coldfix/udiskie | udiskie/prompt.py | https://github.com/coldfix/udiskie/blob/master/udiskie/prompt.py | MIT |
async def __call__(self, device):
"""
Invoke the subprocess to ask the user to enter a password for unlocking
the specified device.
"""
attrs = {attr: getattr(device, attr) for attr in self.used_attrs}
attrs.update(self.extra)
argv = [arg.format(**attrs) for arg i... |
Invoke the subprocess to ask the user to enter a password for unlocking
the specified device.
| __call__ | python | coldfix/udiskie | udiskie/prompt.py | https://github.com/coldfix/udiskie/blob/master/udiskie/prompt.py | MIT |
def connect_event_hook(command_format, mounter):
"""
Command notification tool.
This works similar to Notify, but will issue command instead of showing
the notifications on the desktop. This can then be used to react to events
from shell scripts.
The command can contain modern pythonic format ... |
Command notification tool.
This works similar to Notify, but will issue command instead of showing
the notifications on the desktop. This can then be used to react to events
from shell scripts.
The command can contain modern pythonic format placeholders like:
{device_file}. The following plac... | connect_event_hook | python | coldfix/udiskie | udiskie/prompt.py | https://github.com/coldfix/udiskie/blob/master/udiskie/prompt.py | MIT |
def get_icon_name(self, icon_id: str) -> str:
"""Lookup the system icon name from udisie-internal id."""
icon_theme = Gtk.IconTheme.get_default()
for name in self._icon_names[icon_id]:
if icon_theme.has_icon(name):
return name
elif os.path.exists(name):
... | Lookup the system icon name from udisie-internal id. | get_icon_name | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def get_gicon(self, icon_id: str) -> "Gio.Icon":
"""Lookup Gio.Icon from udiskie-internal id."""
name = self.get_icon_name(icon_id)
if os.path.exists(name):
# TODO (?): we could also add the icon to the theme using
# Gtk.IconTheme.append_search_path or .add_resource_path:... | Lookup Gio.Icon from udiskie-internal id. | get_gicon | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def __init__(self, daemon, icons, actions, flat=True,
quickmenu_actions=None,
checkbox_workaround=False,
update_workaround=False):
"""
Initialize a new menu maker.
:param object mounter: mount operation provider
:param Icons icons: icon... |
Initialize a new menu maker.
:param object mounter: mount operation provider
:param Icons icons: icon provider
:param DeviceActions actions: device actions discovery
:returns: a new menu maker
:rtype: cls
Required keys for the ``_labels``, ``_menu_icons`` and
... | __init__ | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def __call__(self, menu, extended=True):
"""Populate the Gtk.Menu with udiskie mount operations."""
# create actions items
flat = self.flat and not extended
if self._update_workaround:
# When showing menus via AppIndicator3 on sway, the menu geometry
# seems to be... | Populate the Gtk.Menu with udiskie mount operations. | __call__ | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def detect(self):
"""Detect all currently known devices. Returns the root device."""
root = self._actions.detect()
prune_empty_node(root, set())
return root | Detect all currently known devices. Returns the root device. | detect | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def _create_menu(self, items):
"""
Create a menu from the given node.
:param list items: list of menu items
:returns: a new Gtk.Menu object holding all items of the node
"""
menu = Gtk.Menu()
self._create_menu_items(menu, items)
return menu |
Create a menu from the given node.
:param list items: list of menu items
:returns: a new Gtk.Menu object holding all items of the node
| _create_menu | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def _menuitem(self, label, icon, onclick, checked=None):
"""
Create a generic menu item.
:param str label: text
:param Gtk.Image icon: icon (may be ``None``)
:param onclick: onclick handler, either a callable or Gtk.Menu
:returns: the menu item object
:rtype: Gtk... |
Create a generic menu item.
:param str label: text
:param Gtk.Image icon: icon (may be ``None``)
:param onclick: onclick handler, either a callable or Gtk.Menu
:returns: the menu item object
:rtype: Gtk.MenuItem
| _menuitem | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def _prepare_menu(self, node, flat=None):
"""
Prepare the menu hierarchy from the given device tree.
:param Device node: root node of device hierarchy
:returns: menu hierarchy as list
"""
if flat is None:
flat = self.flat
ItemGroup = MenuSection if fl... |
Prepare the menu hierarchy from the given device tree.
:param Device node: root node of device hierarchy
:returns: menu hierarchy as list
| _prepare_menu | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def _collapse_device(self, node, flat):
"""Collapse device hierarchy into a flat folder."""
items = [item
for branch in node.branches
for item in self._collapse_device(branch, flat)
if item]
show_all = not flat or self._quickmenu_actions == 'all... | Collapse device hierarchy into a flat folder. | _collapse_device | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def __init__(self, menumaker, icons, statusicon=None):
"""
Create an object managing a tray icon.
The actual Gtk.StatusIcon is only created as soon as you call show()
for the first time. The reason to delay its creation is that the GTK
icon will be initially visible, which resul... |
Create an object managing a tray icon.
The actual Gtk.StatusIcon is only created as soon as you call show()
for the first time. The reason to delay its creation is that the GTK
icon will be initially visible, which results in a perceptable
flickering.
:param TrayMenu m... | __init__ | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def show(self, show=True):
"""Show or hide the tray icon."""
if show and not self.visible:
self._show()
if not show and self.visible:
self._hide() | Show or hide the tray icon. | show | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def _popup_menu(self, icon, button, time, extended=True):
"""Handle a right click event (show the menu)."""
m = self.create_context_menu(extended)
m.show_all()
m.popup(parent_menu_shell=None,
parent_menu_item=None,
func=icon.position_menu,
... | Handle a right click event (show the menu). | _popup_menu | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def update(self, *args):
"""Show/hide icon depending on whether there are devices."""
if self.smart:
self._icon.show(self.has_menu())
else:
self._icon.show(True) | Show/hide icon depending on whether there are devices. | update | python | coldfix/udiskie | udiskie/tray.py | https://github.com/coldfix/udiskie/blob/master/udiskie/tray.py | MIT |
def object_kind(object_path):
"""
Parse the kind of object from an UDisks2 object path.
Example:
/org/freedesktop/UDisks2/block_devices/sdb1 => device
/org/freedesktop/UDisks2/drives/WDC_WD... => drive
/org/freedesktop/UDisks2/jobs/5 => job
"""
try:
ret... |
Parse the kind of object from an UDisks2 object path.
Example:
/org/freedesktop/UDisks2/block_devices/sdb1 => device
/org/freedesktop/UDisks2/drives/WDC_WD... => drive
/org/freedesktop/UDisks2/jobs/5 => job
| object_kind | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def __getattr__(self, key):
"""Return an AttrDictView for properties on the requested interface."""
interface = Interface[key]
try:
return AttrDictView(self._interfaces_and_properties[interface])
except KeyError:
return PropertiesNotAvailable() | Return an AttrDictView for properties on the requested interface. | __getattr__ | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def __init__(self, daemon, object_path, property_hub, method_hub):
"""Initialize from (Daemon, str, PropertyHub, MethodHub)."""
self._daemon = daemon
self.object_path = object_path
self._P = property_hub
self._M = method_hub | Initialize from (Daemon, str, PropertyHub, MethodHub). | __init__ | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def is_partition(self):
"""Check if the device has a partition slave."""
# Sometimes udisks2 empties the Partition interface before removing
# the device. In this case, we want to report .is_partition=False, so
# properties like .partition_slave will not be used.
return bool(self... | Check if the device has a partition slave. | is_partition | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def _assocdrive(self):
"""
Return associated drive if this is a top level block device.
This method is used internally to unify the behaviour of top level
devices in udisks1 and udisks2.
"""
# NOTE: always fallback to `self` because udisks2 doesn't report
# Crypt... |
Return associated drive if this is a top level block device.
This method is used internally to unify the behaviour of top level
devices in udisks1 and udisks2.
| _assocdrive | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def detach(self, auth_no_user_interaction=None):
"""Detach the device by e.g. powering down the physical port."""
return self._assocdrive._M.Drive.PowerOff(
'(a{sv})',
filter_opt({
'auth.no_user_interaction': ('b', auth_no_user_interaction),
})
... | Detach the device by e.g. powering down the physical port. | detach | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def device_file(self):
"""The filesystem path of the device block file."""
return (
decode_ay(self._P.Block.Device) or
self._P.LoopFile.Filename or '') | The filesystem path of the device block file. | device_file | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def device_id(self):
"""
Return a unique and persistent identifier for the device.
This is the basename (last path component) of the symlink in
`/dev/disk/by-id/`.
"""
if self.is_block:
for filename in self._P.Block.Symlinks:
parts = decode_ay... |
Return a unique and persistent identifier for the device.
This is the basename (last path component) of the symlink in
`/dev/disk/by-id/`.
| device_id | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def drive(self):
"""Get wrapper to the drive containing this device."""
if self.is_drive:
return self
elif self.is_block:
return self._daemon[self._P.Block.Drive]
else:
return None | Get wrapper to the drive containing this device. | drive | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def symlinks(self):
"""Known symlinks of the block device."""
if not self._P.Block.Symlinks:
return []
return [decode_ay(path) for path in self._P.Block.Symlinks] | Known symlinks of the block device. | symlinks | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def luks_cleartext_holder(self):
"""Get wrapper to the unlocked luks cleartext device."""
if not self.is_luks:
return None
for device in self._daemon:
if device.luks_cleartext_slave == self:
return device
return None | Get wrapper to the unlocked luks cleartext device. | luks_cleartext_holder | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def loop_file(self):
"""Get the file backing the loop device."""
return (
decode_ay(self._P.Loop.BackingFile) or
self._P.LoopFile.Filename or '') | Get the file backing the loop device. | loop_file | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def set_autoclear(self, value, auth_no_user_interaction=None):
"""Set autoclear flag for loop partition."""
return self._M.Loop.SetAutoclear(
'(ba{sv})',
value,
filter_opt({
'auth.no_user_interaction': ('b', auth_no_user_interaction),
})
... | Set autoclear flag for loop partition. | set_autoclear | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def is_file(self, path):
"""Comparison by mount and device file path."""
return (samefile(path, self.device_file) or
samefile(path, self.loop_file) or
any(samefile(path, mp) for mp in self.mount_paths) or
sameuuid(path, self.id_uuid) or
sam... | Comparison by mount and device file path. | is_file | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def in_use(self):
"""Check whether this device is in use, i.e. mounted or unlocked."""
if self.is_mounted or self.is_unlocked:
return True
if self.is_partition_table:
for device in self._daemon:
if device.partition_slave == self and device.in_use:
... | Check whether this device is in use, i.e. mounted or unlocked. | in_use | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def ui_label(self):
"""UI string identifying the partition if possible."""
return ': '.join(filter(None, [
self.ui_device_presentation,
self.ui_id_label or self.ui_id_uuid or self.drive_label
])) | UI string identifying the partition if possible. | ui_label | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def ui_device_label(self):
"""UI string identifying the device (drive) if toplevel."""
return ': '.join(filter(None, [
self.ui_device_presentation,
self.loop_file or
self.drive_label or self.ui_id_label or self.ui_id_uuid
])) | UI string identifying the device (drive) if toplevel. | ui_device_label | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def find(self, path):
"""
Get a device proxy by device name or any mount path of the device.
This searches through all accessible devices and compares device
path as well as mount paths.
"""
if isinstance(path, Device):
return path
for device in self:... |
Get a device proxy by device name or any mount path of the device.
This searches through all accessible devices and compares device
path as well as mount paths.
| find | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def __init__(self, proxy, version):
"""Initialize object and start listening to UDisks2 events."""
event_names = ['device_added',
'device_removed',
'device_mounted',
'device_unmounted',
'media_added',
... | Initialize object and start listening to UDisks2 events. | __init__ | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
def get(self, object_path, interfaces_and_properties=None):
"""Create a Device instance from object path."""
# check this before creating the DBus object for more
# controlled behaviour:
if not interfaces_and_properties:
interfaces_and_properties = self._objects.get(object_pa... | Create a Device instance from object path. | get | python | coldfix/udiskie | udiskie/udisks2.py | https://github.com/coldfix/udiskie/blob/master/udiskie/udisks2.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.