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: Fri,  5 Jul 2013 16:55:44 +0000 (UTC)	[thread overview]
Message-ID: <1373042599.63c708b21af0b6aea9ffb881f24a98a3e2281209.dywi@gentoo> (raw)

commit:     63c708b21af0b6aea9ffb881f24a98a3e2281209
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jul  5 16:43:19 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jul  5 16:43:19 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=63c708b2

packageinfo: init_selfdep_validate(), versiontuple

versiontuple implements comparision operations (==,!=,<=,<,>=,>).

---
 roverlay/packageinfo.py  |  28 ++++++++--
 roverlay/versiontuple.py | 141 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 164 insertions(+), 5 deletions(-)

diff --git a/roverlay/packageinfo.py b/roverlay/packageinfo.py
index bef9327..1bcf495 100644
--- a/roverlay/packageinfo.py
+++ b/roverlay/packageinfo.py
@@ -18,6 +18,7 @@ import os.path
 import logging
 
 import roverlay.digest
+import roverlay.versiontuple
 import roverlay.db.distmap
 
 from roverlay          import config, strutil
@@ -128,11 +129,11 @@ class PackageInfo ( object ):
       * **initial_info -- passed to update ( **kw )
       """
       self._info    = dict()
-      self.valid    = True
       self.readonly = False
       self.logger   = LOGGER
       self.selfdeps = None
 
+      #self.selfdeps_valid      = UNDEF
       #self.overlay_package_ref = None
       #self._evars              = dict()
       #self._lazy_actions       = list()
@@ -141,13 +142,26 @@ class PackageInfo ( object ):
       self.update ( **initial_info )
    # --- end of __init__ (...) ---
 
+   def init_selfdep_validate ( self ):
+      """Tells this packageinfo to initialize selfdep validation.
+      Returns True on success (=has selfdeps), else False.
+      """
+      self.selfdeps_valid = True
+      if self.selfdeps:
+         for selfdep in self.selfdeps:
+            selfdep.prepare_selfdep_reduction()
+         return True
+      else:
+         return False
+   # --- end of init_selfdep_validate (...) ---
+
    def has_valid_selfdeps ( self ):
       """Returns True if all selfdeps of this package are valid."""
-      v = self.valid
+      v = self.selfdeps_valid
       if v is True and self.selfdeps is not None and not all (
          map ( lambda d: d.deps_satisfiable(), self.selfdeps )
       ):
-         self.valid = False
+         self.selfdeps_valid = False
          return False
       return v
    # --- end of has_valid_selfdeps (...) ---
@@ -528,7 +542,9 @@ class PackageInfo ( object ):
       """
       rev     = self._info['rev'] + 1 if newrev is None else int ( newrev )
       rev_str = ( '-r' + str ( rev ) ) if rev > 0 else ''
-      vstr    = '.'.join ( str ( k ) for k in self ['version'] ) + rev_str
+      vstr    = (
+         '.'.join ( str ( k ) for k in self._info['version'] ) + rev_str
+      )
 
       # preserve destpath directory
       #  (this allows to handle paths like "a/b.tar/pkg.tgz" properly)
@@ -735,7 +751,9 @@ class PackageInfo ( object ):
 
       try:
          version = tuple ( int ( z ) for z in version_str.split ( '.' ) )
-         self._info ['version'] = version
+         self._info ['version'] = (
+            roverlay.versiontuple.IntVersionTuple ( version )
+         )
       except ValueError as ve:
          # version string is malformed, cannot use it
          self.logger.error (

diff --git a/roverlay/versiontuple.py b/roverlay/versiontuple.py
new file mode 100644
index 0000000..2fa78ba
--- /dev/null
+++ b/roverlay/versiontuple.py
@@ -0,0 +1,141 @@
+# R overlay --
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+import sys
+import itertools
+
+if sys.hexversion >= 0x3000000:
+   _zip_longest = itertools.zip_longest
+else:
+   _zip_longest = itertools.izip_longest
+
+
+# integer representation of version comparision
+VMOD_NONE  = 0
+VMOD_UNDEF = 1
+VMOD_NOT   = 2
+VMOD_EQ    = 4
+VMOD_NE    = VMOD_NOT | VMOD_EQ
+VMOD_GT    = 8
+VMOD_GE    = VMOD_EQ | VMOD_GT
+VMOD_LT    = 16
+VMOD_LE    = VMOD_EQ | VMOD_LT
+
+
+def pkgver_decorator ( func ):
+   def wrapped ( p, *args, **kwargs ):
+      return func ( p._info ['version'], *args, **kwargs )
+   # --- end of wrapped (...) ---
+   wrapped.__name__ = func.__name__
+   wrapped.__doc__  = func.__doc__
+   wrapped.__dict__.update ( func.__dict__ )
+   return wrapped
+# --- end of pkgver_decorator (...) ---
+
+
+class VersionTuple ( tuple ):
+
+   def __init__ ( self, *args, **kwargs ):
+      super ( VersionTuple, self ).__init__ ( *args, **kwargs )
+   # --- end of __init__ (...) ---
+
+   def get_comparator ( self, mode ):
+      if not mode or mode & VMOD_UNDEF:
+         return None
+      elif mode & VMOD_EQ:
+         if mode == VMOD_EQ:
+            return self.__eq__
+         elif mode == VMOD_NE:
+            return self.__ne__
+         elif mode == VMOD_LE:
+            return self.__le__
+         elif mode == VMOD_GE:
+            return self.__ge__
+      elif mode == VMOD_LT:
+         return self.__lt__
+      elif mode == VMOD_GT:
+         return self.__gt__
+
+      return None
+   # --- end of get_comparator (...) ---
+
+   def get_package_comparator ( self, mode ):
+      f = self.get_comparator ( mode )
+      return pkgver_decorator ( f ) if f is not None else None
+   # --- end of get_package_comparator (...) ---
+
+   def set_default_compare ( self, mode ):
+      self._default_compare = self.get_comparator ( mode )
+   # --- end of set_default_compare (...) ---
+
+   def compare ( self, other ):
+      self._default_compare ( other )
+   # --- end of compare (...) ---
+
+# --- end of VersionTuple ---
+
+
+class IntVersionTuple ( VersionTuple ):
+
+   def iter_compare ( self, other ):
+      return _zip_longest ( self, other, fillvalue=0 )
+   # --- end of _iter_compare (...) ---
+
+   def __eq__ ( self, other ):
+      if isinstance ( other, self.__class__ ):
+         return all ( a == b
+            for a, b in _zip_longest ( self, other, fillvalue=0 )
+         )
+      else:
+         return NotImplemented
+   # --- end of __eq__ (...) ---
+
+   def __ne__ ( self, other ):
+      if isinstance ( other, self.__class__ ):
+         return any ( a != b
+            for a, b in _zip_longest ( self, other, fillvalue=0 )
+         )
+      else:
+         return NotImplemented
+   # --- end of __ne__ (...) ---
+
+   def __le__ ( self, other ):
+      if isinstance ( other, self.__class__ ):
+         return all ( a <= b
+            for a, b in _zip_longest ( self, other, fillvalue=0 )
+         )
+      else:
+         return NotImplemented
+   # --- end of __le__ (...) ---
+
+   def __ge__ ( self, other ):
+      if isinstance ( other, self.__class__ ):
+         return all ( a >= b
+            for a, b in _zip_longest ( self, other, fillvalue=0 )
+         )
+      else:
+         return NotImplemented
+   # --- end of __ge__ (...) ---
+
+   def __lt__ ( self, other ):
+      if isinstance ( other, self.__class__ ):
+         return all ( a < b
+            for a, b in _zip_longest ( self, other, fillvalue=0 )
+         )
+      else:
+         return NotImplemented
+   # --- end of __lt__ (...) ---
+
+   def __gt__ ( self, other ):
+      if isinstance ( other, self.__class__ ):
+         return all ( a > b
+            for a, b in _zip_longest ( self, other, fillvalue=0 )
+         )
+      else:
+         return NotImplemented
+   # --- end of __gt__ (...) ---
+
+# --- end of IntVersionTuple ---


             reply	other threads:[~2013-07-05 16:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-05 16:55 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-08 22:47 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=1373042599.63c708b21af0b6aea9ffb881f24a98a3e2281209.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