From 5dd04b0114a2bbc6bd8a47baedc36062f9fa893f Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Mon, 12 Jan 2009 22:43:32 -0600 Subject: [PATCH] Add validate_values() and compare_key() functions to Spec class --- ChangeLog | 4 ++++ modules/catalyst/config.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 05198336..b2d9c65a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 13 Jan 2009; Andrew Gaffney + modules/catalyst/config.py: + Add validate_values() and compare_key() functions to Spec class + 13 Jan 2009; Andrew Gaffney catalyst, modules/catalyst/__init__.py, modules/catalyst/config.py, modules/catalyst/target/generic.py, diff --git a/modules/catalyst/config.py b/modules/catalyst/config.py index 4e372e50..d023e760 100644 --- a/modules/catalyst/config.py +++ b/modules/catalyst/config.py @@ -178,6 +178,24 @@ class Spec: tmp.update(self.values[target]) return tmp + def compare_key(self, key1, key2): + foo = re.compile(key1) + return foo.match(key2) + + def validate_values(self, required, valid, target=None): + if target is None: + target = self.target + values = self.get_values(target) + for x in values: + if x in required or x in valid: + continue + for y in set(required + valid): + if not self.compare_key(y, x): + raise CatalystError("The key '" + x + "' is not a valid key for this target") + for y in required: + if not y in values: + raise CatalystError("The required key '" + y + "' was not found") + class Singleton(type): def __init__(self, *args): -- 2.26.2