From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (unknown [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 3CC221381F3 for ; Tue, 9 Jul 2013 23:14:34 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0C2BFE0C25; Tue, 9 Jul 2013 22:52:12 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D0573E0C5A for ; Tue, 9 Jul 2013 22:51:45 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D4D3833E979 for ; Mon, 8 Jul 2013 22:48:02 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id DB2ACE5458 for ; Mon, 8 Jul 2013 22:47:59 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1373323528.f08cd6669279af63d10b26879c41bb3d9500b6af.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/versiontuple.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: f08cd6669279af63d10b26879c41bb3d9500b6af X-VCS-Branch: gsoc13/next Date: Mon, 8 Jul 2013 22:47:59 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 4b3a4665-3787-491a-ba51-8a8775c21b14 X-Archives-Hash: 2fd362496fdbaf9c8086a65846a62cd6 commit: f08cd6669279af63d10b26879c41bb3d9500b6af Author: André Erdmann mailerd de> AuthorDate: Mon Jul 8 22:45:28 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Mon Jul 8 22:45:28 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=f08cd666 fix package_comparator in roverlay/versiontuple.py --- roverlay/versiontuple.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/roverlay/versiontuple.py b/roverlay/versiontuple.py index 2fa78ba..0ca902a 100644 --- a/roverlay/versiontuple.py +++ b/roverlay/versiontuple.py @@ -24,6 +24,35 @@ VMOD_GE = VMOD_EQ | VMOD_GT VMOD_LT = 16 VMOD_LE = VMOD_EQ | VMOD_LT +VMOD_INVERSE_MAP = { + VMOD_EQ: VMOD_NE, + VMOD_NE: VMOD_EQ, + VMOD_LE: VMOD_GT, + VMOD_LT: VMOD_GE, + VMOD_GE: VMOD_LT, + VMOD_GT: VMOD_LE, +} +VMOD_INVERSE_EQ_PRESERVE_MAP = { + VMOD_EQ: VMOD_NE, + VMOD_NE: VMOD_EQ, + VMOD_LE: VMOD_GE, + VMOD_LT: VMOD_GT, + VMOD_GE: VMOD_LE, + VMOD_GT: VMOD_LT, +} + +def vmod_inverse ( vmod, keep_eq=True ): + """Returns the inverse of vmod (== becomes !=, > becomes <=, ...). + Returns VMOD_UNDEF if the operation is not supported. + + arguments: + * vmod -- int + * keep_eq -- preserve VMOD_EQ + """ + return ( + VMOD_INVERSE_EQ_PRESERVE_MAP if keep_eq else VMOD_INVERSE_MAP + ).get ( vmod, VMOD_UNDEF ) +# --- end of vmod_inverse (...) --- def pkgver_decorator ( func ): def wrapped ( p, *args, **kwargs ): @@ -43,6 +72,17 @@ class VersionTuple ( tuple ): # --- end of __init__ (...) --- def get_comparator ( self, mode ): + """Returns a function "this ~ other" that returns + " ", e.g. <= . + + Returns None if mode is unknown / not supported. + + Note: Use vmod_inverse(mode) to get a comparator "other ~ this" + + arguments: + * mode -- comparator 'mode' (VMOD_EQ, VMOD_NE, VMOD_LE, VMOD_GE, + VMOD_LT, VMOD_GT) + """ if not mode or mode & VMOD_UNDEF: return None elif mode & VMOD_EQ: @@ -62,16 +102,38 @@ class VersionTuple ( tuple ): return None # --- end of get_comparator (...) --- - def get_package_comparator ( self, mode ): - f = self.get_comparator ( mode ) + def get_package_comparator ( self, mode, keep_eq=True ): + """Returns a function "package ~ this" that returns + " " + + Returns None if mode is unknown / not supported. + + arguments: + * mode -- comparator 'mode' that will be inversed + (see get_comparator() and vmod_inverse()) + * keep_eq -- preserve VMOD_EQ when determining the inverse of mode + (Example: '<' becomes '>' if True, else '>=') + """ + f = self.get_comparator ( vmod_inverse ( mode, keep_eq=True ) ) return pkgver_decorator ( f ) if f is not None else None # --- end of get_package_comparator (...) --- def set_default_compare ( self, mode ): + """Sets the default comparator. + + arguments: + * mode -- comparator mode + """ self._default_compare = self.get_comparator ( mode ) # --- end of set_default_compare (...) --- def compare ( self, other ): + """Uses the default comparator to compare this object with another one + and returns the result. + + arguments: + * other -- + """ self._default_compare ( other ) # --- end of compare (...) ---