def connect(self): config = self.config self.device_path = config.port try: #: Save a reference self.protocol.transport = self #: Make the wrapper self._protocol = RawFdProtocol(self, self.protocol) self.connection = SerialPort(self._protocol, config.port, reactor, baudrate=config.baudrate, bytesize=config.bytesize, parity=SERIAL_PARITIES[config.parity], stopbits=config.stopbits, xonxoff=config.xonxoff, rtscts=config.rtscts) # Twisted is missing this if config.dsrdtr: try: self.connection._serial.dsrdtr = True except AttributeError as e: log.warning("{} | dsrdtr is not supported {}".format( config.port, e)) log.debug("{} | opened".format(config.port)) except Exception as e: #: Make sure to log any issues as these tracebacks can get #: squashed by twisted log.error("{} | {}".format(config.port, traceback.format_exc())) raise
def _default_printers(self): if not PRINTER_AVAILABLE: return [] try: return list(cups.Connection().getPrinters().keys()) except Exception as e: log.warning("Failed to get printer list: {}".format(e)) return []
def is_supported(self): try: from enaml.qt import qt_ipython_console return True except ImportError as e: log.warning("IPython console plugin is missing dependencies") log.exception(e) return False
def _refresh_dock_items(self, change=None): """ Reload all DockItems registered by any Plugins Any plugin can add to this list by providing a DockItem extension in their PluginManifest. """ workbench = self.workbench point = workbench.get_extension_point(extensions.DOCK_ITEM_POINT) #: Layout spec layout = {'main': [], 'left': [], 'right': [], 'bottom': [], 'top': []} dock_items = [] for extension in sorted(point.extensions, key=lambda ext: ext.rank): for declaration in extension.get_children(extensions.DockItem): # Load the plugin plugin_id = declaration.plugin_id log.info("Loading plugin {}".format(plugin_id)) plugin = workbench.get_plugin(plugin_id) # Check if it's known dependencies are met if not plugin.is_supported(): log.warning( "Plugin {} reported unsupported".format(plugin_id)) continue # Create the item DockItem = declaration.factory() item = DockItem(plugin=plugin, closable=False) # Add to our layout layout[declaration.layout].append(item.name) # Save it dock_items.append(item) #: Update items log.debug("Updating dock items: {}".format(dock_items)) self.dock_items = dock_items self._refresh_layout(layout)
def find_dev_name(dev): """ Use udevadm to lookup info on a device Parameters ---------- dev: String The device path to lookup, eg /dev/usb/lp1 Returns ------- name: String The device name """ try: cmd = 'udevadm info -a %s' % dev manufacturer = "" product = "" output = subprocess.check_output(cmd.split()) if sys.version_info.major > 2: output = output.decode() for line in output.split('\n'): log.debug(line) m = re.search(r'ATTRS{(.+)}=="(.+)"', line) if m: k, v = m.groups() if k == 'manufacturer': manufacturer = v.strip() elif k == 'product': product = v.strip() if manufacturer and product: return '{} {}'.format(manufacturer, product) log.warning('Could not lookup device info for %s' % dev) except Exception as e: tb = traceback.format_exc() log.warning('Could not lookup device info for %s %s' % (dev, tb)) return 'usb%s' % dev.split('/')[-1]