本文整理汇总了Python中monitor.Monitor.usb_devices_more方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.usb_devices_more方法的具体用法?Python Monitor.usb_devices_more怎么用?Python Monitor.usb_devices_more使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monitor.Monitor
的用法示例。
在下文中一共展示了Monitor.usb_devices_more方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import usb_devices_more [as 别名]
#.........这里部分代码省略.........
"""
if args:
# Backup old name, and reload new one
old_name = self.machine_name
self.machine_name = args[0]
self.load_config()
if not self.config:
print("Invalid virtual machine.")
# Reload old config
self.machine_name = old_name
self.load_config()
else:
print("Virtual machine set.")
return # Return to not show available virtual machines
# Show available virtual machines
print("Set Virtual Machine:", self.machine_name)
print("Virtual Machines: ")
for name in self.vm_names:
print("-", name, "[Active]" if name == self.machine_name else "")
def command_list(self, args):
"""List USB devices connected to virtual machine
Args:
args (list): List arguments
"""
if not self.monitor.connect():
print("Could not connect to monitor.")
return
for device in self.monitor.usb_devices_more():
print("- ID: %s / Device: %s / %s" % (
device.get("id", "Unknown "),
device["device"], device["product"]
))
self.monitor.disconnect()
def command_hostlist(self, args):
"""List USB devices connected to host
Args:
args (list): List arguments
"""
if not self.monitor.connect():
print("Could not connect to monitor.")
return
# Display host usb devices
for device in self.monitor.host_usb_devices_more():
print("- ID: %s / %s %s" % (
device.get("id", "Unknown"), device.get("product", "Unknown"),
"[Connected]" if "device" in device else "",
))
self.monitor.disconnect()
def command_add(self, args):
"""Add USB devices
Args:
args (list): List arguments
"""
# Add all USB devices
if not args:
args = [ # Only add devices without the action of "remove only"
device["id"] for device in self.usb_devices
if device.get("action") != "remove only"
]
else:
args = self.device_names_to_ids(args)
# Add USB device
if not self.monitor_command(lambda m: m.add_usb(args)):
print("Could not add one or more of devices: %s" % args)
def command_remove(self, args):
"""Remove USB devices
Args:
args (list): List arguments
"""
# Remove all USB devices
if not args:
args = [ # Only add devices without the action of "add only"
device["id"] for device in self.usb_devices
if device.get("action") != "add only"
]
else:
args = self.device_names_to_ids(args)
# Remove USB device
if not self.monitor_command(lambda m: m.remove_usb(args)):
print("Could not remove one or more of devices: %s" % args)