def parse_query(self, xml_dom_query_node, caltype, inputf ): ''' Parses a query from XML Calibration File and returns a Calibration request event with the corresponding information. Unfinished: priority parsing value @param xml_dom_query_node: a query XML Dom Node; ie <DOM Element: query at 0x921392c> @type xml_dom_query_node: Dom Element @param caltype: Calibration, ie bias, flat, dark, etc. @type caltype: string @param input: an input fits URI @type input: string @return: Returns a Calibration Request Event. @rtype: CalibrationRequestEvent ''' import Descriptors # bad to load on import, import mess calReqEvent = CalibrationRequest() calReqEvent.caltype = caltype query = xml_dom_query_node if not query.hasAttribute("id"): raise "Improperly formed. QUERY needs an id, for example 'bias'." tempcal = str(query.getAttribute("id")) if( tempcal != caltype ): raise "The id in the query does not match the caltype '"+tempcal+"' '"+str(caltype)+"'." if type( inputf ) == AstroData: ad = inputf elif type( inputf ) == str: ad = AstroData( inputf ) else: raise RuntimeError("Bad Argument: Wrong Type, '%(val)s' '%(typ)s'." %{'val':str(inputf),'typ':str(type(inputf))}) desc = Descriptors.get_calculator( ad ) #=============================================================== # IDENTIFIERS #=============================================================== identifiers = query.getElementsByTagName( "identifier" ) if len( identifiers ) > 0: identifiers = identifiers[0] else: raise "Improperly formed. XML calibration has no identifiers." for child in identifiers.getElementsByTagName( "property" ): #creates dictionary object with multiple values temp = self.parse_property(child, desc, ad) #print "CDL112:", temp calReqEvent.identifiers.update( temp ) #=============================================================== # CRITERIA #=============================================================== criteria = query.getElementsByTagName( "criteria" ) if len( criteria ) > 0: criteria = criteria[0] else: raise "Improperly formed. XML calibration has no criteria" #print 'Locating a %s for %s.' %(str(caltype), str(ad.filename)) #print 'Using the following criteria:' for child in criteria.getElementsByTagName( "property" ): crit = self.parse_property( child, desc, ad ) calReqEvent.criteria.update( crit ) # print self.str_property( crit ) #=============================================================== # PRIORITIES #=============================================================== priorities = query.getElementsByTagName( "priorities" ) if len( priorities ) > 0: priorities = priorities[0] else: raise "Improperly formed. XML calibration has no priorities" for child in priorities.getElementsByTagName( "property" ): calReqEvent.priorities.update( self.parse_property(child, desc, ad) ) calReqEvent.filename = inputf return calReqEvent