def setUpClass(self): self.sconn = None self.serial = None self.device = None d = hw_reg.get_devices() def get_devices_cb(devices): self.device = attach_serial_protocol(devices[0], test=False) self.sconn = self.device.sconn self.sport = self.device.sport d.addCallback(get_devices_cb) return d
def detect_hardware(self, ignored=None): def _ask_user_for_device(devices, callback, splash): controller = DeviceSelectionController(Model(), devices, callback, splash) view = DeviceSelectionView(controller) view.set_parent_view( self.splash.view) # so that we are on top of splash view.show() def _device_select(devices, callback, splash): last_device_udi = config.get_last_device() if last_device_udi and len(devices) == 1: # if theres a saved last_device_udi and there's only one # device (otherwise user has to select one) and udis # match, skip the device selection dialog def serialized_udi_cb(udi): if udi == last_device_udi: callback(devices[0]) return _ask_user_for_device(devices, callback, splash) d = devices[0].get_serialized_udi() d.addCallback(serialized_udi_cb) return # either there's no last_device_udi (first time) or there's # more than one device on the system and user needs to select _ask_user_for_device(devices, callback, splash) def device_serial_eb(failure): from vmc.gtk import dialogs failure.trap(SerialException) message = _('Device setup not completed') details = _(""" Your device has been detected but it has been impossible to connect to it. %s""") % failure.getErrorMessage() dialogs.open_warning_dialog(message, details) _device_select([], self.configure_hardware, self.splash) def device_not_found_eb(failure): failure.trap(ex.DeviceNotFoundError) _device_select([], self.configure_hardware, self.splash) def device_lacks_extractinfo_eb(failure): failure.trap(ex.DeviceLacksExtractInfo) from vmc.gtk import dialogs from vmc.common.shutdown import shutdown_core device = failure.value.args[0] info = dict(name=device.name, vmc=APP_LONG_NAME) message = _('Device setup not completed') details = _(""" Your device "%(name)s" is not properly registered with the kernel. %(vmc)s needs at least two serial ports to communicate with your %(name)s. The program includes a set of udev rules plus some binaries that make sure that your device is always recognised properly. If you've installed from source, then make sure to copy the relevant files in the contrib dir """) % info dialogs.open_warning_dialog(message, details) shutdown_core(delay=.2) def device_timeout_eb(failure): failure.trap(ex.ATTimeout) from vmc.gtk import dialogs from vmc.common.shutdown import shutdown_core message = _('Device not responding') details = _(""" Your device took more than 15 seconds to reply to my last command. Unplug it, plug it again, and try in a moment.""") dialogs.open_warning_dialog(message, details) shutdown_core(delay=.2) def get_devices_cb(devices): _device_select(devices, self.configure_hardware, self.splash) d = hw_reg.get_devices() d.addCallback(get_devices_cb) d.addErrback(device_not_found_eb) d.addErrback(device_lacks_extractinfo_eb) d.addErrback(device_timeout_eb) d.addErrback(device_serial_eb) d.addErrback(log.err)
def detect_hardware(self, ignored=None): def _ask_user_for_device(devices, callback, splash): controller = DeviceSelectionController(Model(), devices, callback, splash) view = DeviceSelectionView(controller) view.set_parent_view(self.splash.view) # so that we are on top of splash view.show() def _device_select(devices, callback, splash): last_device_udi = config.get_last_device() if last_device_udi and len(devices) == 1: # if theres a saved last_device_udi and there's only one # device (otherwise user has to select one) and udis # match, skip the device selection dialog def serialized_udi_cb(udi): if udi == last_device_udi: callback(devices[0]) return _ask_user_for_device(devices, callback, splash) d = devices[0].get_serialized_udi() d.addCallback(serialized_udi_cb) return # either there's no last_device_udi (first time) or there's # more than one device on the system and user needs to select _ask_user_for_device(devices, callback, splash) def device_serial_eb(failure): from vmc.gtk import dialogs failure.trap(SerialException) message = _('Device setup not completed') details = _(""" Your device has been detected but it has been impossible to connect to it. %s""") % failure.getErrorMessage() dialogs.open_warning_dialog(message, details) _device_select([], self.configure_hardware, self.splash) def device_not_found_eb(failure): failure.trap(ex.DeviceNotFoundError) _device_select([], self.configure_hardware, self.splash) def device_lacks_extractinfo_eb(failure): failure.trap(ex.DeviceLacksExtractInfo) from vmc.gtk import dialogs from vmc.common.shutdown import shutdown_core device = failure.value.args[0] info = dict(name=device.name, vmc=APP_LONG_NAME) message = _('Device setup not completed') details = _(""" Your device "%(name)s" is not properly registered with the kernel. %(vmc)s needs at least two serial ports to communicate with your %(name)s. The program includes a set of udev rules plus some binaries that make sure that your device is always recognised properly. If you've installed from source, then make sure to copy the relevant files in the contrib dir """) % info dialogs.open_warning_dialog(message, details) shutdown_core(delay=.2) def device_timeout_eb(failure): failure.trap(ex.ATTimeout) from vmc.gtk import dialogs from vmc.common.shutdown import shutdown_core message = _('Device not responding') details = _(""" Your device took more than 15 seconds to reply to my last command. Unplug it, plug it again, and try in a moment.""") dialogs.open_warning_dialog(message, details) shutdown_core(delay=.2) def get_devices_cb(devices): _device_select(devices, self.configure_hardware, self.splash) d = hw_reg.get_devices() d.addCallback(get_devices_cb) d.addErrback(device_not_found_eb) d.addErrback(device_lacks_extractinfo_eb) d.addErrback(device_timeout_eb) d.addErrback(device_serial_eb) d.addErrback(log.err)
device = devices[0] cli = VMCClient(device, config) cli.start_it() def device_not_found_eb(failure): failure.trap(ex.DeviceNotFoundError) log.msg("I couldn't find a device to use through DBus") reactor.stop() def device_lacks_extractinfo_eb(failure): failure.trap(ex.DeviceLacksExtractInfo) log.msg("Your card has been properly recognized but I couldn't infer") log.msg("from DBus what ports should use to communicate with device") reactor.stop() d = hw_reg.get_devices() d.addCallback(get_devices_cb) d.addErrback(device_not_found_eb) d.addErrback(device_lacks_extractinfo_eb) class VMCClient(object): def __init__(self, device, config): self.device = device self.config = config self.wrapper = None self.connsm = None def start_it(self): if self.config['connect']: statemachine_callbacks = {