Example #1
0
 def DictBodyVisit(self, obj , topology_model):
     """
     Defined to generate the body of the  Python event class
     @parms obj: the instance of the event model to operation on.
     """
     try:
         instance_obj_list = topology_model.get_base_id_dict()[obj.get_component_base_name()]
     except Exception:
         PRINT.info("ERROR: Could not find instance object for component " + obj.get_component_base_name() + ". Check topology model to see if the component was instanced.")
         raise
     
     for instance_obj in instance_obj_list:
         c = EventBody.EventBody()
         if instance_obj[3].get_dict_short_name() != None:
             fname = "{}_{}".format(instance_obj[3].get_dict_short_name() , obj.get_name())
         elif not topology_model.get_prepend_instance_name() and len(instance_obj_list) == 1:
             fname = obj.get_name()
         else:
             fname = "{}_{}".format(instance_obj[0] , obj.get_name())
         c.name = fname
         
         if len(obj.get_ids()) > 1:
             raise Exception("There is more than one event id when creating dictionaries. Check xml of {} or see if multiple explicit IDs exist in the AcConstants.ini file".format(fname))
         try:
             c.id = hex(instance_obj[1]  + int(float(obj.get_ids()[0])))
         except:
             c.id = hex(instance_obj[1]  + int(obj.get_ids()[0] , 16))
             
         c.severity = obj.get_severity()
         c.format_string = obj.get_format_string()
         c.description = obj.get_comment()
         c.component = obj.get_component_name()
         
         c.arglist = list()
         c.ser_import_list = list()
         arg_num = 0
         
         for arg_obj in obj.get_args():
             n = arg_obj.get_name()
             t = arg_obj.get_type()
             s = arg_obj.get_size()
             d = arg_obj.get_comment()
             # convert XML types to Python classes                    
             (type_string,ser_import,type_name,dontcare) = DictTypeConverter.DictTypeConverter().convert(t,s)
             if ser_import != None:
                 c.ser_import_list.append(ser_import)
             # convert format specifier if necessary
             if type_name == "enum":
                 format_string = DictTypeConverter.DictTypeConverter().format_replace(c.format_string,arg_num,'d','s')
                 # check for an error
                 if format_string == None:
                     PRINT.info("Event %s in component %s had error processing format specifier"%(c.name,c.component))
                     sys.exit(-1)
                 else:
                     c.format_string = format_string
                 
             c.arglist.append((n,d,type_string))
             arg_num += 1
         self._writeTmpl(c, self.__fp[fname], "eventBodyVisit")
         self.__fp[fname].close()
Example #2
0
    def DictBodyVisit(self, obj):
        """
        Defined to generate the body of the  Python event class
        @param obj: the instance of the event model to operation on.
        """
        inst = 0
        for id in obj.get_ids():
            c = EventBody.EventBody()
            if len(obj.get_ids()) > 1:
                c.name = obj.get_name() + "_%d" % inst
            else:
                c.name = obj.get_name()
            c.id = id
            c.severity = obj.get_severity()
            c.format_string = obj.get_format_string()
            c.description = obj.get_comment()
            c.component = obj.get_component_name()

            c.arglist = list()
            c.ser_import_list = list()
            arg_num = 0

            for arg_obj in obj.get_args():
                n = arg_obj.get_name()
                t = arg_obj.get_type()
                s = arg_obj.get_size()
                d = arg_obj.get_comment()
                # convert XML types to Python classes
                (
                    type_string,
                    ser_import,
                    type_name,
                    dontcare,
                ) = DictTypeConverter.DictTypeConverter().convert(t, s)
                if ser_import is not None:
                    c.ser_import_list.append(ser_import)
                # convert format specifier if necessary
                if type_name == "enum":
                    format_string = (
                        DictTypeConverter.DictTypeConverter().format_replace(
                            c.format_string, arg_num, "d", "s"))
                    # check for an error
                    if format_string is None:
                        PRINT.info(
                            "Event %s in component %s had error processing format specifier"
                            % (c.name, c.component))
                        sys.exit(-1)
                    else:
                        c.format_string = format_string

                c.arglist.append((n, d, type_string))
                arg_num += 1
            self._writeTmpl(c, self.__fp[inst], "eventBodyVisit")
            self.__fp[inst].close()
            inst += 1