From d0d980c02c4db31334df3859c9533d1c086ab493 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 12 Apr 2009 09:52:06 +0100 Subject: [PATCH] Added VersionRestriction to force a particular version --- zeroinstall/injector/model.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index 9d62f8f..c8b1bc5 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -131,12 +131,37 @@ class Restriction(object): __slots__ = [] def meets_restriction(self, impl): + """Called by the L{Solver} to check whether a particular implementation is acceptable. + @return: False if this implementation is not a possibility + @rtype: bool + """ raise NotImplementedError("Abstract") +class VersionRestriction(Restriction): + """Only select implementations with a particular version number. + @since: 0.40""" + + def __init__(self, version): + """@param version: the required version number + @see: L{parse_version}; use this to pre-process the version number + """ + self.version = version + + def meets_restriction(self, impl): + return impl.version == self.version + + def __str__(self): + return "(restriction: version = %s)" % format_version(self.version) + class VersionRangeRestriction(Restriction): """Only versions within the given range are acceptable""" __slots__ = ['before', 'not_before'] + def __init__(self, before, not_before): + """@param before: chosen versions must be earlier than this + @param not_before: versions must be at least this high + @see: L{parse_version}; use this to pre-process the versions + """ self.before = before self.not_before = not_before -- 2.11.4.GIT