def _load_configuration(self, config_file): try: self.config = StoqdriversConfig(config_file) except ConfigError as e: log.info(e) self.config = None else: # This allows overriding in the config file some or all of the # data that was specified through the constructor section_name = BaseDevice.typename_translate_dict[self.device_type] for field in ['brand', 'device', 'model', 'inverted_drawer']: try: setattr(self, field, self.config.get_option(field, section_name)) except ConfigError: # Field not found, ignore pass # At this point, either we have the data needed to initialize the # device or we will need to bail if (not self.model or not self.brand or (self.interface == BaseDevice.INTERFACE_SERIAL and not self.device and not self._port)): raise ConfigError("Device not specified in config or constructor, giving up") name = "stoqdrivers.%s.%s.%s" % (self.device_dirname, self.brand, self.model) try: module = __import__(name, None, None, 'stoqdevices') except ImportError as reason: raise CriticalError("Could not load driver %s %s: %s" % (self.brand.capitalize(), self.model.upper(), reason)) class_name = self.model driver_class = getattr(module, class_name, None) if not driver_class: raise CriticalError("Device driver at %s needs a class called %s" % (name, class_name)) if self.interface == 'serial': if not self._port: self._port = SerialPort(self.device, self._baudrate) self._driver = driver_class(self._port, consts=self._driver_constants) elif self.interface == 'usb': self._driver = driver_class(self.vendor_id, self.product_id) else: raise NotImplementedError('Interface not implemented') log.info("Device class initialized: brand=%s,device=%s,model=%s" % (self.brand, self.device, self.model)) # This check is necessary but ugly because the configuration code # doesn't understand booleans, and we don't want mismatches if self.inverted_drawer in ("True", True): log.info("Inverting drawer check logic") self._driver.inverted_drawer = True self.check_interfaces()
def _load_configuration(self, config_file): section_name = BaseDevice.typename_translate_dict[self.device_type] if not self.model or not self.brand or (not self.device and not self._port): self.config = StoqdriversConfig(config_file) if not self.config.has_section(section_name): raise ConfigError(_("There is no section named `%s'!") % section_name) self.brand = self.config.get_option("brand", section_name) self.device = self.config.get_option("device", section_name) self.model = self.config.get_option("model", section_name) name = "stoqdrivers.%s.%s.%s" % (self.device_dirname, self.brand, self.model) try: module = __import__(name, None, None, 'stoqdevices') except ImportError, reason: raise CriticalError("Could not load driver %s %s: %s" % (self.brand.capitalize(), self.model.upper(), reason))
def _load_configuration(self, config_file): section_name = BaseDevice.typename_translate_dict[self.device_type] if (not self.model or not self.brand or (self.interface == BaseDevice.INTERFACE_SERIAL and not self.device and not self._port)): self.config = StoqdriversConfig(config_file) if not self.config.has_section(section_name): raise ConfigError( _("There is no section named `%s'!") % section_name) self.brand = self.config.get_option("brand", section_name) self.device = self.config.get_option("device", section_name) self.model = self.config.get_option("model", section_name) name = "stoqdrivers.%s.%s.%s" % (self.device_dirname, self.brand, self.model) try: module = __import__(name, None, None, 'stoqdevices') except ImportError as reason: raise CriticalError( "Could not load driver %s %s: %s" % (self.brand.capitalize(), self.model.upper(), reason)) class_name = self.model driver_class = getattr(module, class_name, None) if not driver_class: raise CriticalError("Device driver at %s needs a class called %s" % (name, class_name)) if self.interface == 'serial': if not self._port: self._port = SerialPort(self.device, self._baudrate) self._driver = driver_class(self._port, consts=self._driver_constants) elif self.interface == 'usb': self._driver = driver_class(self.vendor_id, self.product_id) else: raise NotImplementedError('Interface not implemented') log.info(("Config data: brand=%s,device=%s,model=%s" % (self.brand, self.device, self.model))) self.check_interfaces()