예제 #1
0
    def register_rule(self, rule_class, details):
        """
        Takes a newly loaded copy of a rule (MappingRule or MergeRule),
        validates it, stores it for later instantiation, and adds it to the
        file tracking list.

        :param rule_class:
        :param details:
        :return:
        """
        class_name = rule_class.__name__

        # do not load or watch invalid rules
        invalidation = self._get_invalidation(rule_class, details)
        if invalidation is not None:
            printer.out(invalidation)
            return

        _set_rdescripts(rule_class.mapping, class_name)
        '''
        rule should be safe for loading at this point: register it
        but do not load here -- this method only registers
        '''
        managed_rule = ManagedRule(rule_class, details)
        self._managed_rules[class_name] = managed_rule
        # set up de/activation command
        self._activator.register_rule(managed_rule)
        # watch this file for future changes
        if not details.watch_exclusion:
            self._reload_observable.register_watched_file(
                details.get_filepath())
예제 #2
0
파일: mergerule.py 프로젝트: pimp22/Caster
 def __init__(self, name=None, mapping=None, extras=None, defaults=None):
     _name = name or self.get_rule_class_name()
     _mapping = mapping or self.mapping.copy()
     _extras = extras or self.extras[:]
     _defaults = defaults or self.defaults.copy()
     _set_rdescripts(_mapping, _name)
     #
     super(MergeRule, self).__init__(name=_name,
                                     mapping=_mapping,
                                     extras=_extras,
                                     defaults=_defaults)