public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/
Date: Mon,  8 Jul 2013 22:47:59 +0000 (UTC)	[thread overview]
Message-ID: <1373323528.f08cd6669279af63d10b26879c41bb3d9500b6af.dywi@gentoo> (raw)

commit:     f08cd6669279af63d10b26879c41bb3d9500b6af
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Jul  8 22:45:28 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> 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
+      "<this version> <mode, e.g. VMOD_EQ> <other version>", e.g. <a> <= <b>.
+
+      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
+      "<package version> <inversed mode> <this version>"
+
+      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 (...) ---
 


             reply	other threads:[~2013-07-09 23:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-08 22:47 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-07-23  7:51 [gentoo-commits] proj/R_overlay:master commit in: roverlay/ André Erdmann
2013-07-23  7:51 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23  7:51 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-19 18:00 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-19 18:00 André Erdmann
2013-07-17 18:05 André Erdmann
2013-07-15 22:31 André Erdmann
2013-07-12 13:57 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-12 13:57 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-08 22:47 André Erdmann
2013-07-05 16:55 André Erdmann
2013-07-05 16:55 André Erdmann
2013-07-05 16:55 André Erdmann
2013-06-22 15:24 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-22 15:14 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-22 15:24 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-22 15:14 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-22 15:24 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-20 23:40 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-22 15:24 [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-20 23:40 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-19 18:58 André Erdmann
2013-06-19 18:58 André Erdmann
2013-06-05 18:08 André Erdmann
2013-06-05 18:08 André Erdmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373323528.f08cd6669279af63d10b26879c41bb3d9500b6af.dywi@gentoo \
    --to=dywi@mailerd.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox