diff options
author | 2014-07-18 01:53:48 +0200 | |
---|---|---|
committer | 2014-07-18 01:58:33 +0200 | |
commit | c56757276df58cf03a19512d3ed4f9d36cef6f06 (patch) | |
tree | 4656d97c3ede1c036d6b92bc3ffd57c9401646ad /roverlay | |
parent | add-policy rule gen: BitmaskMapCreator (diff) | |
download | R_overlay-c56757276df58cf03a19512d3ed4f9d36cef6f06.tar.gz R_overlay-c56757276df58cf03a19512d3ed4f9d36cef6f06.tar.bz2 R_overlay-c56757276df58cf03a19512d3ed4f9d36cef6f06.zip |
packagerules/rules->PackageRules: append_rule()
Adds a rule to an (possibly) already-sorted PackageRules object and gives it the
lowest priority (highest int, 1+max(self._rules priority).
Will be used to add generated rules that should be applied last (add-policy).
Diffstat (limited to 'roverlay')
-rw-r--r-- | roverlay/packagerules/rules.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/roverlay/packagerules/rules.py b/roverlay/packagerules/rules.py index 5cbe600..0dd0d3d 100644 --- a/roverlay/packagerules/rules.py +++ b/roverlay/packagerules/rules.py @@ -47,6 +47,34 @@ class PackageRules ( roverlay.packagerules.abstract.rules.NestedPackageRule ): self.is_toplevel = True # --- end of __init__ (...) --- + def append_rule ( self, rule, prepare_rule=True ): + """ + Sets the given rule's priority to 1 + lowest prio of already-added rules + (so that it will be applied last) and adds it. + + Optionally prepares the rule so that prepare() doesn't need to be + called afterwards, assuming that the PackageRules was already prepared. + + arguments: + * rule -- + * prepare_rule -- whether to prepare the added rule or not + Defaults to True. + """ + if self._rules: + rule.priority = 1 + max ( rule.priority for rule in self._rules ) + else: + rule.priority = 0 + + self.add_rule ( rule ) + + if prepare_rule: + rule.set_logger ( self.logger.getChild ( 'nested' ) ) + rule.prepare() + # no need to sort self._rules + # self._rules [-1].prio > self._rules [-2].prio + # <=> sorted if self.prepare() has been called before + # --- end of append_rule (...) --- + def _gen_rules_str ( self, level ): if level == 0: last_rule_index = len ( self._rules ) - 1 |