Example #1
0
    def save(self):
        from models import Parameter
        from modoboa.lib.formutils import SeparatorField

        for name, value in self.cleaned_data.items():
            if type(self.fields[name]) is SeparatorField:
                continue
            fullname = "%s.%s" % (self.app, name.upper())
            try:
                p = Parameter.objects.get(name=fullname)
            except Parameter.DoesNotExist:
                p = Parameter()
                p.name = fullname
            self._save_parameter(p, name, value)
Example #2
0
    def save(self):
        from models import Parameter
        from modoboa.lib.formutils import SeparatorField

        for name, value in self.cleaned_data.items():
            if type(self.fields[name]) is SeparatorField:
                continue
            fullname = "%s.%s" % (self.app, name.upper())
            try:
                p = Parameter.objects.get(name=fullname)
            except Parameter.DoesNotExist:
                p = Parameter()
                p.name = fullname
            self._save_parameter(p, name, value)
Example #3
0
def save_admin(name, value, app=None):
    from models import Parameter

    if app is None:
        app = __guess_extension()
    __is_defined(app, 'A', name)
    fullname = "%s.%s" % (app, name)
    try:
        p = Parameter.objects.get(name=fullname)
    except Parameter.DoesNotExist:
        p = Parameter()
        p.name = fullname
        p.value = None
    f = get_parameter_form('A', name, app)
    f()._save_parameter(p, name, value)
Example #4
0
def save_admin(name, value, app=None):
    from models import Parameter

    if app is None:
        app = __guess_extension()
    __is_defined(app, 'A', name)
    fullname = "%s.%s" % (app, name)
    try:
        p = Parameter.objects.get(name=fullname)
    except Parameter.DoesNotExist:
        p = Parameter()
        p.name = fullname
        p.value = None
    f = get_parameter_form('A', name, app)
    f()._save_parameter(p, name, value)
Example #5
0
def addparameter_response(model_id, interface_id):
    if not session.get("logged_in"):
        return redirect(url_for("login"))
    add_parameter_response = ParameterResponseForm()
    submit = SubmitForm()
    if submit.validate_on_submit():
        add = Parameter(interface_id=interface_id,
                        parameter_type=20,
                        parameter_group_id=add_parameter_response.parameter_group_id.data,
                        parameter_name=add_parameter_response.parameter_name.data,
                        necessary=add_parameter_response.necessary.data,
                        type=add_parameter_response.type.data,
                        default=add_parameter_response.default.data,
                        remark=add_parameter_response.remark.data,
                        level=add_parameter_response.level.data)
        db.session.add(add)
        db.session.commit()
        return redirect(url_for("parameter_response",
                                model_id=model_id,
                                interface_id=interface_id))
    return render_template("addparameter_response.html",
                           add_parameter_response=add_parameter_response,
                           model_id=model_id,
                           interface_id=interface_id,
                           submit=submit)
Example #6
0
def save_offers_to_db(db, offers: List[dict]):
    # TODO make versions for offers (probably by date)
    for offer in offers:
        vader_id = offer["vader_id"]
        good_orm = Good(vader_id=vader_id)
        parameters = [
            Parameter(good=good_orm, name=name, value=value)
            for name, value in offer["params"].items()
        ]
        good_orm.parameters = parameters
        db.add(good_orm)
    db.commit()
Example #7
0
    def add_param(self, name, upper, lower, tolerance):
        param = Parameter.query.filter_by(name=name).first()
        if param:
            # Should just overwrite it.
            return param

        p = Parameter(name, upper, lower, tolerance)
        db.session.add(p)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
        return p
Example #8
0
def read_db():
    parameters = []
    conn_db = pymysql.connect(host=conf['db']['host'],user=conf['db']['user'],password=conf['db']['password'],db=conf['db']['db_name'],charset='utf8',cursorclass=pymysql.cursors.DictCursor)
    try:
        with conn_db.cursor() as cursor:
            cursor.execute("SELECT * FROM `parameters`")
            rows = cursor.fetchall()
            cursor.execute("SELECT * FROM `laws`")
            laws = cursor.fetchall()
        for row in rows:
            law_name = next(x for x in laws if x['id']==row['law_id'])
            parameters.append(Parameter(row['id'], row['name'], row['unit'], law_name, row['period'], row['noise'],row['mean'],row['dispersion'],row['min'],row['max']))
    finally:
        conn_db.close()

    return parameters
Example #9
0
def parseInsertStatement(sql):
    parameters = []
    result = re.findall(Patterns.insert_value, sql)
    if len(result) == 2:
        columns = re.sub('[\(\)]', '', result[0]).split(',')
        values = re.sub('[\(\)]', '', result[1]).split(',')
        if len(columns) != len(values):
            raise ParametersMismatch(
                'Invalid query , Please verify the parameters and values',
                status_code=400)
        unkownKeyIndex = 0
        for i in range(0, len(columns)):
            value = values[i]
            if value != '?':
                key = value
            else:
                unkownKeyIndex = unkownKeyIndex + 1
                key = '?' + str(unkownKeyIndex)
            parameters.append(Parameter(columns[i], value, key))
    return parameters
Example #10
0
    def create(self, the_parsed_component_xml, parsed_port_xml_list, parsed_serializable_list):
        """
        Create a component model here.
        """
        x = the_parsed_component_xml
        comp_obj = x.get_component()
        comp_port_obj_list = x.get_ports()
        comp_command_obj_list = x.get_commands()
        comp_channel_obj_list = x.get_channels()
        comp_parameter_obj_list = x.get_parameters()
        comp_event_obj_list = x.get_events()
        comp_internal_interface_obj_list = x.get_internal_interfaces()
        
        #
        comp_namespace = comp_obj.get_namespace()
        comp_name      = comp_obj.get_name()
        comp_kind      = comp_obj.get_kind()
        comp_comment   = comp_obj.get_comment()
        comp_modeler  = comp_obj.get_modeler()
        if comp_namespace == None:
            comp_full_name = comp_name
        else:
            comp_full_name = comp_namespace + "::" + comp_name  
        # get original filename here...
        comp_xml_filename = x.get_xml_filename()
        #
        comp_xml_port_files = x.get_port_type_files()
        comp_c_header_files = x.get_header_files()
        has_guarded_ports = False
        
        num_async_ports = 0
        num_sync_ports = 0 # includes guarded ports
        
        #
        #print ("Component: %s"%comp_name)
        incl_list = []
        #
        # Create list of ports with all ports of the component.
        #
        port_obj_list = []
        for port_obj in comp_port_obj_list:
            n=port_obj.get_name()
            t=port_obj.get_type()
            d=port_obj.get_direction()
            s=port_obj.get_sync()
            r=port_obj.get_role()
            if (s == 'sync' or s == 'guarded'):
                num_sync_ports += 1
            if s == 'async':
                num_async_ports += 1
            p=port_obj.get_priority()
            if s == "guarded":
                has_guarded_ports = True
            c=port_obj.get_comment()
            m=port_obj.get_max_number()
            f=port_obj.get_full()
            port_obj_list.append(Port.Port(n, t, d, s, p, f, c, max_number=m, role=r ))
        command_obj_list = []
        for command_obj in comp_command_obj_list:
            m=command_obj.get_mnemonic()
            o=command_obj.get_opcodes()
            s=command_obj.get_sync()
            p=command_obj.get_priority()
            f=command_obj.get_full()
            if s == "guarded":
                has_guarded_ports = True
            if (s == 'sync' or s == "guarded"):
                num_sync_ports += 1
            if s == 'async':
                num_async_ports += 1
            c=command_obj.get_comment()
            arg_obj_list = []
            for a in command_obj.get_args():
                name    = a.get_name()
                atype   = a.get_type()
                comment = a.get_comment()
                size    = a.get_size()
                arg_obj_list.append(Arg.Arg(name, atype, None, size, comment))
            command_obj_list.append(Command.Command(m, o, arg_obj_list, s, p, c, comp_xml_filename,comp_full_name , component_base_name = comp_name , base_opcode = command_obj.get_base_opcode() , full  = f))
            
            
        channel_obj_list = []
        for channel_obj in comp_channel_obj_list:
            i=channel_obj.get_ids()
            n=channel_obj.get_name()
            t=channel_obj.get_type()
            s=channel_obj.get_size()
            c=channel_obj.get_comment()
            a=channel_obj.get_abbrev()
            f=channel_obj.get_format_string()
            u=channel_obj.get_update()
            l=channel_obj.get_limits()
            channel_obj_list.append(
                Channel.Channel(ids=i, 
                                name=n, 
                                ctype=t, 
                                size=s, 
                                abbrev=a, 
                                format_string=f, 
                                update=u,
                                limits=l,
                                comment=c,
                                xml_filename=comp_xml_filename,
                                component_name=comp_full_name,
                                component_base_name = comp_name))
        
        event_obj_list = []
        for event_obj in comp_event_obj_list:
            i=event_obj.get_ids()
            n=event_obj.get_name()
            s=event_obj.get_severity()
            f=event_obj.get_format_string()
            t=event_obj.get_throttle()
            c=event_obj.get_comment()
            arg_obj_list = []
            for a in event_obj.get_args():
                name    = a.get_name()
                atype   = a.get_type()
                size    = a.get_size()
                comment = a.get_comment()
                arg_obj_list.append(Arg.Arg(name, atype, None, size, comment))
            event_obj_list.append(Event.Event(i, n, s, f, t, arg_obj_list, c, comp_xml_filename,comp_full_name , component_base_name = comp_name))
            
        internal_interface_obj_list = []
        for internal_interface_obj in comp_internal_interface_obj_list:
            # borrow this for check
            num_async_ports += 1
            n=internal_interface_obj.get_name()
            p=internal_interface_obj.get_priority()
            f=internal_interface_obj.get_full()
            c=internal_interface_obj.get_comment()
            arg_obj_list = []
            for a in internal_interface_obj.get_args():
                name    = a.get_name()
                atype   = a.get_type()
                size    = a.get_size()
                comment = a.get_comment()
                arg_obj_list.append(Arg.Arg(name, atype, None, size, comment))
            internal_interface_obj_list.append(InternalInterface.InternalInterface(n, p, f , arg_obj_list, c, comp_xml_filename,comp_full_name))

        parameter_obj_list = []
        for parameter_obj in comp_parameter_obj_list:
            i=parameter_obj.get_ids()
            n=parameter_obj.get_name()
            t=parameter_obj.get_type()
            set_ops = parameter_obj.get_set_opcodes()
            save_ops = parameter_obj.get_save_opcodes()
            d=parameter_obj.get_default()
            s=parameter_obj.get_size()
            c=parameter_obj.get_comment()
            parameter_obj_list.append(Parameter.Parameter(i, n, t, set_ops, save_ops, d, s, c, comp_xml_filename,comp_full_name , base_setop = parameter_obj.get_base_setop() , base_saveop = parameter_obj.get_base_saveop()))
            
        serializable_obj_list = []
        for serializable_obj in parsed_serializable_list:
            f=serializable_obj.get_xml_filename()
            n=serializable_obj.get_name()
            ns=serializable_obj.get_namespace()
            c=serializable_obj.get_comment()
            x=serializable_obj.get_includes()
            # shouldn't be c includes
            m=serializable_obj.get_members()
            t=serializable_obj.get_typeid()
            serializable_obj_list.append(Serialize.Serialize(f,n,ns,c,x,None,m,t))
                    
        #
        # Check here to make sure all the port types in the component XML
        # exist in the port XMLs
        #
        interface_xml_list = [parsed_port_obj.get_interface().get_name() for parsed_port_obj in parsed_port_xml_list]
        for port_obj in port_obj_list:
            t = port_obj.get_type()
            ## Skip if special port. (If there role)
            ## Namespaces for special ports are set above
            if (t not in interface_xml_list) and (t.lower() != "serial") and (port_obj.get_role() == None):
                PRINT.info("ERROR: Missing port type definition in component XML (name: %s, type: %s)" % (port_obj.get_name(),t))
                sys.exit(-1)
        #
        # Check here to make sure all the port types in the component XML
        # exist in the port XMLs
        #

#        interface_xml_list = [parsed_command_obj.get_interface().get_name() for parsed_command_obj in parsed_command_xml_list]
#        print interface_xml_list
#        for command_obj in command_obj_list:
#            t = command_obj.get_type()
#            if (t not in interface_xml_list):
#                PRINT.info("ERROR: Missing command type definition in component XML (name: %s, type: %s)" % (command_obj.get_type(),t))
#                sys.exit(-1)
#       #
        # Add port type specifics to port object.
        # Specifics are things like: args, includes, etc.
        for port_obj in port_obj_list:

            for parsed_port_obj in parsed_port_xml_list:
                #print "Meta: Name: %s, Type: %s" % (port_obj.get_name(), port_obj.get_type())
                #print "Meta: Port Type: %s, Port Interface: %s" % (port_obj.get_type(),parsed_port_obj.get_interface().get_name())
                    
                if port_obj.get_type() == parsed_port_obj.get_interface().get_name():
                    arg_obj_list = []
                    incl_list = parsed_port_obj.get_include_header_files()
                    namespace = parsed_port_obj.get_interface().get_namespace()
                    if_comment = parsed_port_obj.get_interface().get_comment()
                    return_type = parsed_port_obj.get_interface().get_return_type()
                    return_modifier = parsed_port_obj.get_interface().get_return_modifier()
            
                    for a in parsed_port_obj.get_args():
                        name    = a.get_name()
                        atype   = a.get_type()
                        comment = a.get_comment()
                        modifier = a.get_modifier()
                        size = a.get_size()
                        arg_obj_list.append(Arg.Arg(name, atype, modifier, size, comment))
                    port_obj.set(namespace, arg_obj_list, incl_list, None, if_comment)
                    port_obj.set_return(return_type,return_modifier)
                    # check some rules
                    # 1) No return values for async ports
                    if (port_obj.get_sync() == "async") and (return_type != None):
                        PRINT.info("ERROR: %s: Port \"%s\" cannot be asynchronous and have a return value" % (the_parsed_component_xml.get_xml_filename(), port_obj.get_name()))
                        sys.exit(-1)
                    # 2) Serial ports can't have roles
                    if (port_obj.get_type() == "Serial") and (port_obj.get_role() != None):
                        PRINT.info("ERROR: %s: Port \"%s\" cannot have a role and be a serialized port" % (the_parsed_component_xml.get_xml_filename(), port_obj.get_name()))
                        sys.exit(-1)
                         
        # check some component/port rules
        # 1) Active or queued need at least one async port/command
        if (comp_kind == "active") or (comp_kind == "queued"):
            if num_async_ports == 0 and len(parameter_obj_list) == 0:
                PRINT.info("ERROR: %s: Active/Queued component \"%s\" needs at least one async port, command, or interface" % (the_parsed_component_xml.get_xml_filename(), comp_name))
                sys.exit(-1)
        # 2) Queued component needs at least one sync port/command
        if comp_kind == "queued":
            if num_sync_ports == 0:
                PRINT.info("ERROR: %s: Queued component \"%s\" needs at least one sync/guarded port or command" % (the_parsed_component_xml.get_xml_filename(), comp_name))
                sys.exit(-1)
                 

        #
        # Instance the component here...
        #
        the_component = Component.Component(comp_namespace, comp_name, comp_kind, comp_comment, comp_modeler, port_obj_list, command_obj_list, channel_obj_list, parameter_obj_list, event_obj_list, internal_interface_obj_list, serializable_obj_list, comp_xml_filename)
        the_component.set_xml_port_files(comp_xml_port_files)
        the_component.set_c_header_files(comp_c_header_files)
        if (has_guarded_ports):
            the_component.set_has_guarded_ports()
        
        #for p in the_component.get_ports():
        #    print p.get_name(), p.get_namespace()
        #    for a in p.get_args():
        #        print a.get_name(), a.get_type(), a.get_modifier()

        return the_component
Example #11
0
    # Fetch its ID and some info
    s = Station(api_url, station)
    # Search linked channels
    url = channel_url + '&station=%s' % s.code
    channels = get(url)
    for channel in channels:
        c = Channel(api_url, channel)
        c.station = s  # Add a link from channel to station
        s.channels.append(c)
        if c.network and c.network.code not in s.networks:
            s.networks.append(c.network.code)
        # Search linked parameters
        url = params_url + '&channel=%s' % c.id
        params = get(url)
        for param in params:
            p = Parameter(api_url, param)
            c.parameters.append(p)
    # Search equipments linked to the station, but not linked to a channel
    station_equipment_url = equipment_url + '&station=%s' % searched_site_code
    equipments = get(station_equipment_url)
    for equipment in equipments:
        e = Equipment(api_url, equipment)
        s.equipments.append(e)
    # Remember station
    result.append(s)

# FINALLY DISPLAY RESULT
for station in result:
    print(s)

# Bye bye!