def create_esi_db(self, db_name): try: if os.path.exists(db_name): os.remove(db_name) YoUtil.debug_print('DB file deleted:',db_name) self.con = sqlite3.connect(db_name) cur = self.con.cursor() YoUtil.debug_print('SQLite version: ',cur.fetchone()) with self.con: cur.execute("CREATE TABLE IF NOT EXISTS Vendors(VendorId INT, Name TEXT, Path TEXT, App TEXT)") cur.execute("CREATE TABLE IF NOT EXISTS Devices(VendorId INT, productCode INT, revisionNumber INT, Name TEXT, Xml TEXT)") files_pair = self.get_ESI_files() for pair in files_pair: esi_path = pair[1] vendor_id,vendor_name = self.get_ESI_info(esi_path) if vendor_id!= 0: with self.con: cur.execute("INSERT INTO Vendors (VendorId,Name,Path,App) VALUES(?,?,?,?)",(vendor_id,vendor_name,esi_path,pair[0])) device_list = self.get_ESI_devices() for device in device_list: with self.con: cur.execute("INSERT INTO Devices (VendorId,productCode,revisionNumber,Name) VALUES(?,?,?,?)",(vendor_id,device[0],device[1],device[2])) return True except sqlite3.Error as e: print('DB Error: ',e) return False finally: if self.con: self.con.close()
def load(self): YoUtil.debug_print('loading ->', self.path) self.tree = ET() self.tree.parse(self.path) root = self.tree.getroot() xml_list = root.findall('Workspace/Targets/item') if xml_list != None: #YoUtil.debug_print('lst',xml_list) for xml_node in xml_list: tm = target_model(xml_node) self.target_list.append(tm)
def get_ESI_devices(self): ret = list() #devices if self.xml_esi!= None: YoUtil.debug_print('read devices of esi=',self.esi_path) xml_list_device = self.xml_esi.findall('Descriptions/Devices/Device') YoUtil.debug_print('num of devices in esi=',len(xml_list_device)) for xml_device in xml_list_device: pc = None rev=None name=None xml_type = xml_device.find('Type') if xml_type != None: msg1 = '' if 'ProductCode' in xml_type.attrib.keys(): pc = YoUtil.get_int(xml_type.attrib['ProductCode']) msg1 = msg1+'ProductCode='+hex(pc) if 'RevisionNo' in xml_type.attrib.keys(): rev = YoUtil.get_int(xml_type.attrib['RevisionNo']) msg1= msg1+' RevisionNo:'+hex(rev) if len(msg1)>0: YoUtil.debug_print(msg1,'') if pc != None: ret.append((pc,rev,name)) return ret
def load(self): YoUtil.debug_print('loading ->', self.path) self.tree = ET() self.tree.parse(self.path) root = self.tree.getroot() xml_list = root.findall('GLOBAL_PARAMS/NAME') if xml_list != None: #YoUtil.debug_print('xml_list=',xml_list) for xml_name in xml_list: res_id = xml_name.get('RES_ID') #YoUtil.debug_print('Res_ID=',res_id) if res_id != None: self.res_id = res_id xml_list = root.findall('MOTION_DEVICES/NODE') if xml_list != None: #YoUtil.debug_print('Nodes xml_list=',xml_list) for xml_node in xml_list: self.load_node(xml_node) xml_list = root.findall('IO_DEVICES/NODE') if xml_list != None: #YoUtil.debug_print('Nodes xml_list=',xml_list) for xml_node in xml_list: self.load_io(xml_node) xml_list = root.findall('GENERAL_DEVICES/NODE') if xml_list != None: #YoUtil.debug_print('Nodes xml_list=',xml_list) for xml_node in xml_list: self.load_general(xml_node) xml_list = root.findall('VIRTUAL_OBJECTS/VIRTUAL_OBJECT') if xml_list != None: #YoUtil.debug_print('Nodes xml_list=',xml_list) for xml_node in xml_list: self.load_virtual(xml_node)
def get_devices(self, vendor_id,productCode,revisionNumber): ret = list() files = self.get_ESI_files_by_vendor(vendor_id) YoUtil.debug_print('num of files=',len(files)) for file_path in files: xml_esi = self.load_esi(file_path) if xml_esi!= None: xml_list_device = xml_esi.findall('Descriptions/Devices/Device') YoUtil.debug_print('num of devices=',len(xml_list_device)) for xml_device in xml_list_device: xml_type = xml_device.find('Type') if xml_type != None: pc = YoUtil.get_int(xml_type.attrib['ProductCode']) YoUtil.debug_print('ProductCode=',pc) if pc == productCode: ret.append(file_path) return ret