def wget_download(self, command, destPath): try: os.chdir(destPath) except: print_ERROR(self, "destine path at: " + destPath + " doesn't exists") return -1 subprocess.call(command, shell=True) return 1
def wget_download (self,command,destPath): try: os.chdir(destPath) except: print_ERROR(self,"destine path at: " + destPath + " doesn't exists") return -1 subprocess.call(command,shell=True) return 1
def get_XML_data(xml_file): try: file = open(xml_file) data = file.read() file.close() return data except IOError: print_ERROR(self,"No XML file found!") return -1
def XML_2_str_parm(xml_file, parameter): xml_data = get_XML_data(xml_file) if xml_data == -1: print_ERROR(self,"Couldn't get any parameter because coudln't found the file") return -1 dom = parseString(xml_data) value = dom.getElementsByTagName(parameter)[0].childNodes[0] parameter = int(value.nodeValue) return parameter
def get_XML_data(xml_file): try: file = open(xml_file) data = file.read() file.close() return data except IOError: print_ERROR(self, "No XML file found!") return -1
def XML_2_str_parm(xml_file, parameter): xml_data = get_XML_data(xml_file) if xml_data == -1: print_ERROR( self, "Couldn't get any parameter because coudln't found the file") return -1 dom = parseString(xml_data) value = dom.getElementsByTagName(parameter)[0].childNodes[0] parameter = int(value.nodeValue) return parameter
def get_parameters(self, parameters, destinePath, fileName): if not fileName: print_ERROR(self,"You must specify a filename!") return if type(parameters)==type(dict()): settings.get_dictionary_parameters(self,parameters,destinePath,fileName) elif type(parameters)==type(list()): settings.get_list_parameters(self,parameters,destinePath,fileName) elif type(parameters)==type(str()): settings.get_string_parameter(self,parameter,destinePath,fileName) else: print_ERROR(self,"I can't read this parameter, please be more specific!") return
def download_settings(cam, parmameters): #def download_settings(cam, parmameters, settDic): cam.get_parameters(parmameters,DESTPATH,"camera_settings") #download the camera settings using the dictionary as a reference. try: tree = ElTree.parse(os.path.join(DESTPATH,"camera_settings.xml")) root = tree.getroot() print_DEBUG(camera,"'tree' is:" + str(tree)) #debug print_DEBUG(camera,"'root' is" + str(root)) #debug except: print_ERROR(camera,"Something went wrong while parsing 'camera_settings.xml'") error = True else: for child in tree.iter(): for c in child: #settDic[c.tag] = c.text cam.implant_camera_setting(c.tag, c.text)
def get_parameters(self, parameters, destinePath, fileName): if not fileName: print_ERROR(self, "You must specify a filename!") return if type(parameters) == type(dict()): settings.get_dictionary_parameters(self, parameters, destinePath, fileName) elif type(parameters) == type(list()): settings.get_list_parameters(self, parameters, destinePath, fileName) elif type(parameters) == type(str()): settings.get_string_parameter(self, parameter, destinePath, fileName) else: print_ERROR( self, "I can't read this parameter, please be more specific!") return
def set_parameters(self, parameters): if type(parameters)==type(dict()): settings.set_dictionary_parameters(self,parameters) elif type(parameters)==type(list()): print_ERROR(self,"I need a dictionary of parameters along with it's corresponding values!") return elif type(parameters)==type(str()): print_ERROR(self,"I need a dictionary of parameters along with it's corresponding values!") return else: print_ERROR(self,"I can't read this parameter, please be more specific!")
def set_parameters(self, parameters): if type(parameters) == type(dict()): settings.set_dictionary_parameters(self, parameters) elif type(parameters) == type(list()): print_ERROR( self, "I need a dictionary of parameters along with it's corresponding values!" ) return elif type(parameters) == type(str()): print_ERROR( self, "I need a dictionary of parameters along with it's corresponding values!" ) return else: print_ERROR( self, "I can't read this parameter, please be more specific!")
def set_default_settings(self, XMLparmFile): import xml.etree.ElementTree as ElTree changes = False error = False currentParmsDic = {} sendParmsDic = {} maxLengthWan = 0 maxLengthCam = 0 self.AUTO_CONFG = True try: print_DEBUG(self,"obre el 'try' amb XMLparmFile:" + XMLparmFile) #debug tree = ElTree.parse(XMLparmFile) print_DEBUG(self,"crea el 'tree'") #debug root = tree.getroot() rint_DEBUG(self,"pren l'arrel") #debug print_DEBUG(self,"'tree' is:" + str(tree)) #debug print_DEBUG(self,"'root' is" + str(root)) #debug except: print_ERROR(self,"Something went wrong while parsing " + XMLparmFile) error = True else: for child in tree.iter(): for c in child: self.DIC_SETTINGS[c.tag] = c.text keyListWan = self.DIC_SETTINGS.keys() if error is not True: self.get_parameters(self.DIC_SETTINGS,self.PATH,"camera_settings") try: tree = ElTree.parse(os.path.join(DESTPATH,"camera_settings.xml")) root = tree.getroot() print_DEBUG(self,"'tree' is:" + str(tree)) #debug print_DEBUG(self,"'root' is" + str(root)) #debug except: print_ERROR(self,"Something went wrong while parsing 'camera_settings.xml'") error = True else: for child in tree.iter(): for c in child: currentParmsDic[c.tag] = c.text keyListCam = currentParmsDic.keys() if error is not True: wanVal = "" camVal = "" w = 0 maxLengthWan = len(keyListWan) print_DEBUG(self,"'maxLengthWan' is: " + str(maxLengthWan)) #debug maxLengthCam = len(keyListCam) print_DEBUG(self,"'maxLengthCam' is: " + str(maxLengthCam)) #debug for w in range(maxLengthWan): wanVal = keyListWan[w] c = 0 for c in range(maxLengthCam): camVal = keyListCam[c] if (wanVal == camVal): if (self.DIC_SETTINGS[wanVal] == currentParmsDic[camVal]): print_DEBUG(self,wanVal + " is " + self.DIC_SETTINGS[wanVal] + " on both dictionaries") break else: #TODO add a pooliong system, which will allow multi-threading sendParmsDic[wanVal] = self.DIC_SETTINGS[wanVal] changes = True c = c + 1 w = w + 1 else: print_ERROR(self,"The process failed and will end unsuccessfully") return if changes: set_parameters(sendParmsDic) print_CASUAL(self,"All new values uploaded to the camera") else: print_CASUAL(self,"No values uploaded to the camera") #set_parameters(self.DIC_SETTINGS) if self.DIC_SETTINGS["AUTOEXP_ON"] == 1: self.AUTO_EXP_STATE = False else: self.AUTO_EXP_STATE = True if self.DIC_SETTINGS["WB_EN"] == 1: self.AUTO_WB_STATE = False else: self.AUTO_WB_STATE = True self.AUTO_CONFG = False
def setupCamera_1(): changes = False error = False wantedParmsDic = {} cameraParmsDic = {} sendParmsDic = {} maxLengthWan = 0 maxLengthCam = 0 try: camera1 except NameError: camera1 = ElpAPI.core(HOST1) #creates camera only if it doesn't exists before else: print_CASUAL(camera1,"'camera1' object already created") try: tree = ElTree.parse(os.path.join(DESTPATH,"wanted_settings1.xml")) root = tree.getroot() except: print_ERROR(camera1,"Something went wrong while parsing 'wanted_settings.xml'") error = True else: for child in tree.iter(): for c in child: wantedParmsDic[c.tag] = c.text #created a dictionary from known sources. keyListWan = wantedParmsDic.keys() camera1.get_parameters(wantedParmsDic,DESTPATH,"camera_settings1") #download the camera settings using the dictionary as a reference. try: tree = ElTree.parse(os.path.join(DESTPATH,"camera_settings1.xml")) root = tree.getroot() print_DEBUG(camera1,"'tree' is:" + str(tree)) #debug print_DEBUG(camera1,"'root' is" + str(root)) #debug except: print_ERROR(camera1,"Something went wrong while parsing 'camera_settings1.xml'") error = True else: for child in tree.iter(): for c in child: cameraParmsDic[c.tag] = c.text camera1.implant_camera_setting(c.tag, c.text) #created a new dictionary with the settings the camera is using.7 #download_settings(camera, wantedParmsDic, cameraParmsDic) #download_settings(camera1, wantedParmsDic) keyListCam = cameraParmsDic.keys() #keyListCam = camera.DIC_SETTINGS.keys() #keyListCam = camera1.gather_camera_settings() if error is not True: wanVal = "" camVal = "" w = 0 maxLengthWan = len(keyListWan) print_DEBUG(camera1,"'maxLengthWan' is: " + str(maxLengthWan)) #debug maxLengthCam = len(keyListCam) print_DEBUG(camera1,"'maxLengthCam' is: " + str(maxLengthCam)) #debug for w in range(maxLengthWan): wanVal = keyListWan[w] c = 0 for c in range(maxLengthCam): camVal = keyListCam[c] if (wanVal == camVal): if (wantedParmsDic[wanVal] == cameraParmsDic[camVal]): print_DEBUG(camera1,wanVal + " is " + wantedParmsDic[wanVal] + " on both dictionaries") break else: #TODO add a pooliong system, which will allow multi-threading sendParmsDic[wanVal] = wantedParmsDic[wanVal] changes = True c = c + 1 w = w + 1 else: print_ERROR(camera1,"The process failed and will end unsuccessfully") return if changes: camera1.set_parameters(sendParmsDic) print_CASUAL(camera1,"All new values uploaded to the camera") else: print_CASUAL(camera1,"No values uploaded to the camera")
def set_default_settings(self, XMLparmFile): import xml.etree.ElementTree as ElTree changes = False error = False currentParmsDic = {} sendParmsDic = {} maxLengthWan = 0 maxLengthCam = 0 self.AUTO_CONFG = True try: print_DEBUG(self, "obre el 'try' amb XMLparmFile:" + XMLparmFile) #debug tree = ElTree.parse(XMLparmFile) print_DEBUG(self, "crea el 'tree'") #debug root = tree.getroot() rint_DEBUG(self, "pren l'arrel") #debug print_DEBUG(self, "'tree' is:" + str(tree)) #debug print_DEBUG(self, "'root' is" + str(root)) #debug except: print_ERROR(self, "Something went wrong while parsing " + XMLparmFile) error = True else: for child in tree.iter(): for c in child: self.DIC_SETTINGS[c.tag] = c.text keyListWan = self.DIC_SETTINGS.keys() if error is not True: self.get_parameters(self.DIC_SETTINGS, self.PATH, "camera_settings") try: tree = ElTree.parse( os.path.join(DESTPATH, "camera_settings.xml")) root = tree.getroot() print_DEBUG(self, "'tree' is:" + str(tree)) #debug print_DEBUG(self, "'root' is" + str(root)) #debug except: print_ERROR( self, "Something went wrong while parsing 'camera_settings.xml'") error = True else: for child in tree.iter(): for c in child: currentParmsDic[c.tag] = c.text keyListCam = currentParmsDic.keys() if error is not True: wanVal = "" camVal = "" w = 0 maxLengthWan = len(keyListWan) print_DEBUG(self, "'maxLengthWan' is: " + str(maxLengthWan)) #debug maxLengthCam = len(keyListCam) print_DEBUG(self, "'maxLengthCam' is: " + str(maxLengthCam)) #debug for w in range(maxLengthWan): wanVal = keyListWan[w] c = 0 for c in range(maxLengthCam): camVal = keyListCam[c] if (wanVal == camVal): if (self.DIC_SETTINGS[wanVal] == currentParmsDic[camVal]): print_DEBUG( self, wanVal + " is " + self.DIC_SETTINGS[wanVal] + " on both dictionaries") break else: #TODO add a pooliong system, which will allow multi-threading sendParmsDic[wanVal] = self.DIC_SETTINGS[wanVal] changes = True c = c + 1 w = w + 1 else: print_ERROR(self, "The process failed and will end unsuccessfully") return if changes: set_parameters(sendParmsDic) print_CASUAL(self, "All new values uploaded to the camera") else: print_CASUAL(self, "No values uploaded to the camera") #set_parameters(self.DIC_SETTINGS) if self.DIC_SETTINGS["AUTOEXP_ON"] == 1: self.AUTO_EXP_STATE = False else: self.AUTO_EXP_STATE = True if self.DIC_SETTINGS["WB_EN"] == 1: self.AUTO_WB_STATE = False else: self.AUTO_WB_STATE = True self.AUTO_CONFG = False
def setupCamera(): changes = False error = False wantedParmsDic = {} cameraParmsDic = {} sendParmsDic = {} maxLengthWan = 0 maxLengthCam = 0 #autoKillSwitch.go() #TODO all this stuff is reserverd for the future #autoResolution.go() #TODO the same above #autoColourt.go() #TODO add a colour selection system, the same above try: camera except NameError: camera = ElpAPI.core( HOST) #creates camera only if it doesn't exists before else: print_CASUAL(camera, "'camera' object already created") try: tree = ElTree.parse(os.path.join(DESTPATH, "wanted_settings.xml")) root = tree.getroot() except: print_ERROR( camera, "Something went wrong while parsing 'wanted_settings.xml'") error = True else: for child in tree.iter(): for c in child: wantedParmsDic[c.tag] = c.text #created a dictionary from known sources. keyListWan = wantedParmsDic.keys() camera.get_parameters(wantedParmsDic, DESTPATH, "camera_settings") #download the camera settings using the dictionary as a reference. try: tree = ElTree.parse(os.path.join(DESTPATH, "camera_settings.xml")) root = tree.getroot() print_DEBUG(camera, "'tree' is:" + str(tree)) #debug print_DEBUG(camera, "'root' is" + str(root)) #debug except: print_ERROR( camera, "Something went wrong while parsing 'camera_settings.xml'") error = True else: for child in tree.iter(): for c in child: cameraParmsDic[c.tag] = c.text #created a new dictionary with the settings the camera is using. keyListCam = cameraParmsDic.keys() if error is not True: wanVal = "" camVal = "" w = 0 maxLengthWan = len(keyListWan) print_DEBUG(camera, "'maxLengthWan' is: " + str(maxLengthWan)) #debug maxLengthCam = len(keyListCam) print_DEBUG(camera, "'maxLengthCam' is: " + str(maxLengthCam)) #debug for w in range(maxLengthWan): wanVal = keyListWan[w] c = 0 for c in range(maxLengthCam): camVal = keyListCam[c] if (wanVal == camVal): if (wantedParmsDic[wanVal] == cameraParmsDic[camVal]): print_DEBUG( camera, wanVal + " is " + wantedParmsDic[wanVal] + " on both dictionaries") break else: #TODO add a pooliong system, which will allow multi-threading sendParmsDic[wanVal] = wantedParmsDic[wanVal] changes = True c = c + 1 w = w + 1 else: print_ERROR(camera, "The process failed and will end unsuccessfully") return if changes: camera.set_parameters(sendParmsDic) print_CASUAL(camera, "All new values uploaded to the camera") else: print_CASUAL(camera, "No values uploaded to the camera")