diff options
author | mike <michael.jmontcalm@gmail.com> | 2009-12-01 20:11:43 (GMT) |
---|---|---|
committer | mike <michael.jmontcalm@gmail.com> | 2009-12-01 20:11:43 (GMT) |
commit | 2c8fe66c0f7490c8aaaae27b4977b987001c6b71 (patch) | |
tree | 32d4ce390d853fb5a8405e71cfb37b6b52988e3b /tutorius/constraints.py | |
parent | b7586af9d127e7954674d13ea185a0e84d197c37 (diff) | |
parent | 50ec9ae6ebc7ecc088b5e0a6b79688a717271955 (diff) |
Merge branch 'master' of git://git.sugarlabs.org/tutorius/simpoirs-clone
Conflicts:
src/extensions/tutoriusremote.py
tutorius/TProbe.py
tutorius/creator.py
Diffstat (limited to 'tutorius/constraints.py')
-rw-r--r-- | tutorius/constraints.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tutorius/constraints.py b/tutorius/constraints.py index 519bce8..cd71167 100644 --- a/tutorius/constraints.py +++ b/tutorius/constraints.py @@ -24,6 +24,8 @@ for some properties. # For the File Constraint import os +# For the Resource Constraint +import re class ConstraintException(Exception): """ @@ -214,3 +216,40 @@ class FileConstraint(Constraint): raise FileConstraintError("Non-existing file : %s"%value) return +class ResourceConstraintError(ConstraintException): + pass + +class ResourceConstraint(Constraint): + """ + Ensures that the value is looking like a resource name, like + <filename>_<GUID>[.<extension>]. We are not validating that this is a + valid resource for the reason that the property does not have any notion + of tutorial guid. + + TODO : Find a way to properly validate resources by looking them up in the + Vault. + """ + + # Regular expression to parse a resource-like name + resource_regexp_text = "(.+)_([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})(\..*)?$" + resource_regexp = re.compile(resource_regexp_text) + + def validate(self, value): + # TODO : Validate that we will not use an empty resource or if we can + # have transitory resource names + if value is None: + raise ResourceConstraintError("Resource not allowed to have a null value!") + + # Special case : We allow the empty resource name for now + if value == "": + return value + + # Attempt to see if the value has a resource name inside it + match = self.resource_regexp.search(value) + + # If there was no match on the reg exp + if not match: + raise ResourceConstraintError("Resource name does not seem to be valid : %s" % value) + + # If the name matched, then the value is _PROBABLY_ good + return value |