Add validate_values() and compare_key() functions to Spec class
authorAndrew Gaffney <agaffney@gentoo.org>
Tue, 13 Jan 2009 04:43:32 +0000 (22:43 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Tue, 13 Jan 2009 04:43:32 +0000 (22:43 -0600)
ChangeLog
modules/catalyst/config.py

index 05198336a640f6ebc06f8ae44cabebf5c08ed0a5..b2d9c65ac435600bd22be4e54c1026022b979d4c 100644 (file)
--- 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 <agaffney@gentoo.org>
+  modules/catalyst/config.py:
+  Add validate_values() and compare_key() functions to Spec class
+
   13 Jan 2009; Andrew Gaffney <agaffney@gentoo.org> catalyst,
   modules/catalyst/__init__.py, modules/catalyst/config.py,
   modules/catalyst/target/generic.py,
index 4e372e50d4242e0d3361b9cb618893e34ec8d9b9..d023e7602fc09a709bce2bfbae2a0e87a4d5b8d9 100644 (file)
@@ -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):