From e1a06a116279807d8a3fb5565dd6365c44f2333a Mon Sep 17 00:00:00 2001 From: mhagger Date: Thu, 24 Mar 2011 04:25:38 +0000 Subject: [PATCH] Add ConditionalPropertySetter This can be useful when an existing property setter should just be applied in certain cases (e.g. when a CVSFile is binary). Patch by: Robin Stocker git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5330 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/property_setters.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cvs2svn_lib/property_setters.py b/cvs2svn_lib/property_setters.py index 96557f64..686452db 100644 --- a/cvs2svn_lib/property_setters.py +++ b/cvs2svn_lib/property_setters.py @@ -428,6 +428,21 @@ class KeywordsPropertySetter(FilePropertySetter): self.maybe_set_property(cvs_file, 'svn:keywords', self.value) +class ConditionalPropertySetter(object): + """Delegate to the passed property setters when the passed predicate applies. + The predicate should be a function that takes a CVSFile or CVSRevision + argument and return True if the property setters should be applied.""" + + def __init__(self, predicate, *property_setters): + self.predicate = predicate + self.property_setters = property_setters + + def set_properties(self, cvs_file_or_rev): + if self.predicate(cvs_file_or_rev): + for property_setter in self.property_setters: + property_setter.set_properties(cvs_file_or_rev) + + class RevisionPropertySetter: """Abstract class for objects that can set properties on a CVSRevision.""" -- 2.11.4.GIT