Esempio n. 1
0
    def set_entry(self, entry, value, module=None, widget=None):
        """
        Sets an entry of this core's configuration
        """
        if entry not in self._local_config_keys:
            db = self._core.get_db()
            if module is not None:
                stmnt = "SELECT CNF_PARAM, CNO_ID FROM CONFIG INNER JOIN CONFIGOWNERS ON (CNF_CNO_ID = CNO_ID) \
                            WHERE CNF_PARAM = ? AND CNO_MOD_ID = ? ;"
                res = db.query(self._core, stmnt, (str(entry), module.get_id()))
                row = res.fetchonemap()
                if row is not None:
                    cnf_relation_id = row["CNO_ID"]
                    stmnt = "UPDATE CONFIG SET CNF_VAL = ? WHERE CNF_CNO_ID = ? ;"
                    db.query(self._core, stmnt, (str(value), cnf_relation_id), commit=True)
                else:
                    cnf_relation_id = db.get_seq_next("CNO_GEN")
                    stmnt = "INSERT INTO CONFIGOWNERS (CNO_ID, CNO_MOD_ID, CNO_WGT_ID) VALUES (?,?,NULL) ;"
                    db.query(self._core, stmnt, (cnf_relation_id, module.get_id()),commit=True)
                    stmnt = "INSERT INTO CONFIG (CNF_PARAM, CNF_VAL, CNF_CNO_ID) VALUES (?,?,?) ;"
                    db.query(self._core, stmnt, (str(entry), str(value), str(cnf_relation_id)), commit=True)

            elif widget is not None:
                stmnt = "SELECT CNF_PARAM, CNO_ID FROM CONFIG INNER JOIN CONFIGOWNERS ON (CNF_CNO_ID = CNO_ID) \
                            WHERE CNF_PARAM = ? AND CNO_WGT_ID = ? ;"
                res = db.query(self._core, stmnt, (str(entry), widget.get_id()))
                row = res.fetchonemap()
                if row is not None:
                    cnf_relation_id = row["CNO_ID"]
                    stmnt = "UPDATE CONFIG SET CNF_VAL = ? WHERE CNF_CNO_ID = ? ;"
                    db.query(self._core, stmnt, (str(value), cnf_relation_id), commit=True)
                else:
                    cnf_relation_id = db.get_seq_next("CNO_GEN")
                    stmnt = "INSERT INTO CONFIGOWNERS (CNO_ID, CNO_MOD_ID, CNO_WGT_ID) VALUES (?,NULL,?) ;"
                    db.query(self._core, stmnt, (cnf_relation_id, widget.get_id()),commit=True)
                    stmnt = "INSERT INTO CONFIG (CNF_PARAM, CNF_VAL, CNF_CNO_ID) VALUES (?,?,?) ;"
                    db.query(self._core, stmnt, (str(entry), str(value), str(cnf_relation_id)), commit=True)

            else:
                stmnt = "SELECT CNF_PARAM, CNO_ID FROM CONFIG INNER JOIN CONFIGOWNERS ON (CNF_CNO_ID = CNO_ID) \
                            WHERE CNF_PARAM = ? AND CNO_MOD_ID IS NULL AND CNO_WGT_ID IS NULL;"
                res = db.query(self._core, stmnt, (str(entry),))
                row = res.fetchonemap()
                if row is not None:
                    cnf_relation_id = row["CNO_ID"]
                    stmnt = "UPDATE CONFIG SET CNF_VAL = ? WHERE CNF_CNO_ID = ? ;"
                    db.query(self._core, stmnt, (str(value), cnf_relation_id), commit=True)
                else:
                    cnf_relation_id = db.get_seq_next("CNO_GEN")
                    stmnt = "INSERT INTO CONFIGOWNERS (CNO_ID, CNO_MOD_ID, CNO_WGT_ID) VALUES (?,NULL,NULL) ;"
                    db.query(self._core, stmnt, (cnf_relation_id),commit=True)
                    stmnt = "INSERT INTO CONFIG (CNF_PARAM, CNF_VAL, CNF_CNO_ID) VALUES (?,?,?) ;"
                    db.query(self._core, stmnt, (str(entry), str(value), str(cnf_relation_id)), commit=True)
                
        else:
            raise ConfigurationException(ConfigurationException.get_msg(2))
Esempio n. 2
0
    def get_entry(self, entry, module=None, widget=None):
        """
        Returns a entry of this core's configuration
        """
        if module is not None:
            prefix = module.get_name()+"::"
        elif widget is not None:
            prefix = widget.get_module().get_name()+"::"+str(widget.get_id())+"::"
        else:
            prefix = ""

        entry = prefix+entry    
        if entry in self._configuration.keys():
            return self._configuration[entry]
        raise ConfigurationException(ConfigurationException.get_msg(1))