def loadRuleSet(table_uuid): Django.logger.debug('Loading Rule set...') try: ruleTable = PolicyRuleTableModel.objects.get(uuid = table_uuid) except: return list() rules = PolicyRuleModel.objects.filter(RuleTableName = ruleTable.name).order_by('RulePosition') ruleSet = [] #The rules sort by priority for rule in rules: ruleObj= ParseEngine.parseRule(rule.Rule) ruleObj._uuid = rule.RuleUUID ruleEntry = RuleEntry(ruleObj,rule.RuleIsEnabled) ruleSet.append(ruleEntry) return ruleSet
def loadRuleSet(table_uuid): SQLAlchemy.logger.debug('Loading Rule set...') try: ruleTable = DB_SESSION.query(PolicyRuleTableModel).filter(PolicyRuleTableModel.uuid == table_uuid).first() except: return list() rules = DB_SESSION.query(PolicyRuleModel).filter(PolicyRuleModel.RuleTableName == ruleTable.name).order_by(PolicyRuleModel.RulePosition).all() ruleSet = [] #The rules sort by priority for rule in rules: ruleObj= ParseEngine.parseRule(rule.Rule) ruleObj._uuid = rule.RuleUUID ruleEntry = RuleEntry(ruleObj,rule.RuleIsEnabled) ruleSet.append(ruleEntry) DB_SESSION.expunge_all() return ruleSet
def addRule(self,string,enabled=True,pos=None,parser=None,pBackend=None,persist=True): if not parser: parser = self._parser rule = ParseEngine.parseRule(string, parser) rule.setUUID(uuid.uuid4().hex) with self._mutex: if pos > len(self._ruleSet): #raise Exception("Invalid position") self._ruleSet.append(RuleEntry(rule,enabled)) elif pos !=None: self._ruleSet.insert(pos,RuleEntry(rule,enabled)) else: self._ruleSet.append(RuleEntry(rule,enabled)) if self._persist: self.save()