Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_device_tree(self):
"""Get a tree of all devices."""
root = DevNode(None, None, [], None)
device_nodes = {
dev.object_path: DevNode(dev, dev.parent_object_path, [],
self._ignore_device(dev))
for dev in self.udisks
}
for node in device_nodes.values():
device_nodes.get(node.root, root).children.append(node)
device_nodes['/'] = root
for node in device_nodes.values():
node.children.sort(key=DevNode._sort_key)
# use parent as fallback, update top->down:
def propagate_ignored(node):
for child in node.children:
if child.ignored is None:
child.ignored = node.ignored
propagate_ignored(child)
propagate_ignored(root)
def get_device_tree(self):
"""Get a tree of all devices."""
root = DevNode(None, None, [], None)
device_nodes = {
dev.object_path: DevNode(dev, dev.parent_object_path, [],
self._ignore_device(dev))
for dev in self.udisks
}
for node in device_nodes.values():
device_nodes.get(node.root, root).children.append(node)
device_nodes['/'] = root
for node in device_nodes.values():
node.children.sort(key=DevNode._sort_key)
# use parent as fallback, update top->down:
def propagate_ignored(node):
for child in node.children:
if child.ignored is None:
child.ignored = node.ignored
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._sort_key)
if not node.ignored and node.device
and (node.root == '/' or nodes[node.root].ignored)]