def convert(self, data): """ Convert data to the type of value :return: The data of the value :rtype: depending of the type of the value """ if data is not None: try: if self.type == 0x01: #Bool return string_to_bool(data) elif self.type == 0x02 or self.type == 0x04 or self.type == 0x07: #Byte or Int or Short return int(data) elif self.type == 0x03: #Decimal return float(data) elif self.type == 0x08: #String return data elif self.type == 0x16: #Array return data.split('|') logger.warning('[%s] - Do not convert data %s to %s.', self.__class__.__name__, data, VALUE_DESC[self.type]['label']) return data except Exception: logger.exception('[%s] - Exception when converting data %s to %s', self.__class__.__name__, data, VALUE_DESC[self.type]['label']) return None return None
def _create_db_engine(self): """Create the sql alchemy engine """ logger.debug(u'[%s] - Create db engine', self.__class__.__name__) #~ self.stop_db() #print self.options if self.dbengine is not None: return True alembic = self.options.get_options('database') self.dbauto_migrate = string_to_bool(alembic['auto_migrate']) if 'auto_migrate' in alembic else None self.dbengine = create_db_engine(self.options) return True