1
0
Fork 0

Merge pull request #229 from yarda/drop-instance-option

Added drop option allowing dropping options from inherited plugins
This commit is contained in:
Jaroslav Škarvada 2019-12-01 11:01:09 +01:00 committed by GitHub
commit 72b96352d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -43,6 +43,10 @@ class Merger(object):
profile_a.units[unit_name].script_pre = unit.script_pre
if unit.script_post is not None:
profile_a.units[unit_name].script_post = unit.script_post
if unit.drop is not None:
for option in unit.drop:
profile_a.units[unit_name].options.pop(option, None)
unit.drop = None
if unit_name == "script" and profile_a.units[unit_name].options.get("script", None) is not None:
script = profile_a.units[unit_name].options.get("script", None)
profile_a.units[unit_name].options.update(unit.options)

View file

@ -1,11 +1,12 @@
import collections
import re
class Unit(object):
"""
Unit description.
"""
__slots__ = [ "_name", "_type", "_enabled", "_replace", "_devices", "_devices_udev_regex", \
__slots__ = [ "_name", "_type", "_enabled", "_replace", "_drop", "_devices", "_devices_udev_regex", \
"_cpuinfo_regex", "_uname_regex", "_script_pre", "_script_post", "_options" ]
def __init__(self, name, config):
@ -13,6 +14,9 @@ class Unit(object):
self._type = config.pop("type", self._name)
self._enabled = config.pop("enabled", True) in [True, "True", "true", 1, "1"]
self._replace = config.pop("replace", False) in [True, "True", "true", 1, "1"]
self._drop = config.pop("drop", None)
if self._drop is not None:
self._drop = re.split(r"\b\s*[,;]\s*", str(self._drop))
self._devices = config.pop("devices", "*")
self._devices_udev_regex = config.pop("devices_udev_regex", None)
self._cpuinfo_regex = config.pop("cpuinfo_regex", None)
@ -45,6 +49,14 @@ class Unit(object):
def replace(self):
return self._replace
@property
def drop(self):
return self._drop
@drop.setter
def drop(self, value):
self._drop = value
@property
def devices(self):
return self._devices