forked from dictation-toolbox/Caster
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
11 changes: 11 additions & 0 deletions
11
castervoice/lib/ctrl/mgr/validation/combo/base_combo_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from castervoice.lib.ctrl.mgr.errors.base_class_error import DontUseBaseClassError | ||
|
||
|
||
class BaseComboValidator(object): | ||
""" | ||
Identifies and rejects invalid rules; has access to their | ||
RuleDetails objects. | ||
""" | ||
|
||
def validate(self, rule, details): | ||
raise DontUseBaseClassError(self) |
12 changes: 12 additions & 0 deletions
12
castervoice/lib/ctrl/mgr/validation/combo/combo_validation_delegator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ComboValidationDelegator(object): | ||
|
||
def __init__(self, *validator_delegates): | ||
self._validator_delegates = validator_delegates | ||
|
||
def validate(self, rule, details): | ||
invalidations = [] | ||
for delegate in self._validator_delegates: | ||
invalidation = delegate.validate(rule, details) | ||
if invalidation is not None: | ||
invalidations.append(invalidation) | ||
return None if len(invalidations) == 0 else ", ".join(invalidations) |
26 changes: 26 additions & 0 deletions
26
castervoice/lib/ctrl/mgr/validation/combo/non_empty_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from castervoice.lib.ctrl.mgr.validation.combo.base_combo_validator import BaseComboValidator | ||
from castervoice.lib.merge.selfmod.selfmodrule import BaseSelfModifyingRule | ||
|
||
|
||
class RuleNonEmptyValidator(BaseComboValidator): | ||
""" | ||
Any static rule should have at least one command to start. | ||
Some selfmod rules don't have any rules the first time they | ||
are instantiated, but then immediately fill in and "reboot" | ||
themselves. | ||
SikuliRule is not a selfmod rule, but it kind of works like | ||
one, so it is also exempted. | ||
""" | ||
|
||
def validate(self, rule, details): | ||
invalidations = [] | ||
if len(rule.mapping) == 0 and not self._rule_is_exempt(rule): | ||
invalidations.append("rules must have at least one command") | ||
return None if len(invalidations) == 0 else ", ".join(invalidations) | ||
|
||
def _rule_is_exempt(self, rule): | ||
selfmod = isinstance(rule, BaseSelfModifyingRule) | ||
sikuli = rule.__class__.__name__ == "SikuliRule" | ||
return selfmod or sikuli |
15 changes: 15 additions & 0 deletions
15
castervoice/lib/ctrl/mgr/validation/combo/rule_family_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from dragonfly import MappingRule | ||
|
||
from castervoice.lib.ctrl.mgr.validation.combo.base_combo_validator import BaseComboValidator | ||
from castervoice.lib.merge.mergerule import MergeRule | ||
|
||
|
||
class RuleFamilyValidator(BaseComboValidator): | ||
|
||
def validate(self, rule, details): | ||
invalidations = [] | ||
if isinstance(rule, MappingRule) and details.declared_ccrtype is not None: | ||
invalidations.append("MappingRules must not have a ccrtype") | ||
if isinstance(rule, MergeRule) and details.declared_ccrtype is None: | ||
invalidations.append("MergeRules must have a ccrtype") | ||
return None if len(invalidations) == 0 else ", ".join(invalidations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters