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:master commit in: roverlay/db/
Date: Tue,  3 Sep 2013 12:21:09 +0000 (UTC)	[thread overview]
Message-ID: <1378210682.924bba0dca52503b87a73ce386c01bf33e2fa008.dywi@gentoo> (raw)

commit:     924bba0dca52503b87a73ce386c01bf33e2fa008
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Sep  3 12:18:02 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Sep  3 12:18:02 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=924bba0d

distmap: make "volatile" a ref to a pkg info

DistMapInfo: make_volatile()/make_persistent() for "converting" entries into
volatile/non-volatile form.

---
 roverlay/db/distmap.py | 93 +++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 76 insertions(+), 17 deletions(-)

diff --git a/roverlay/db/distmap.py b/roverlay/db/distmap.py
index 16d1b97..d400a75 100644
--- a/roverlay/db/distmap.py
+++ b/roverlay/db/distmap.py
@@ -22,6 +22,11 @@ import roverlay.stats.collector
 __all__ = [ 'DistMapInfo', 'FileDistMap', ]
 
 
+
+class DistmapException ( Exception ):
+   pass
+
+
 class DistMapInfo ( object ):
    """Distmap entry"""
 
@@ -41,14 +46,11 @@ class DistMapInfo ( object ):
    @classmethod
    def volatile_from_package_info ( cls, p_info, backref=None ):
       instance = cls ( *p_info.get_distmap_value ( no_digest=True ) )
-      instance.volatile = True
-      if backref is not None:
-         instance.add_backref ( backref )
-      return instance
+      return instance.make_volatile ( p_info, backref=backref )
    # --- end of volatile_from_package_info (...) ---
 
    def __init__ (
-      self, distfile, repo_name, repo_file, sha256, volatile=False
+      self, distfile, repo_name, repo_file, sha256, volatile=None
    ):
       """Distmap entry constructor.
 
@@ -57,8 +59,10 @@ class DistMapInfo ( object ):
       * repo_name -- name of the repo that owns the package file
       * repo_file -- path of the package file relative to the repo
       * sha256    -- file checksum
-      * volatile  -- whether this entry should be persistent (False) or
-                     not (True). Defaults to False.
+      * volatile  -- a reference to a PackageInfo instance or None
+                     None indicates that this entry should be persistent,
+                     whereas "not None" indicates a "volatile" entry.
+                     Defaults to None.
       """
       super ( DistMapInfo, self ).__init__()
 
@@ -76,6 +80,33 @@ class DistMapInfo ( object ):
          self.repo_file = repo_file if repo_file is not None else self.UNSET
    # --- end of __init__ (...) ---
 
+   def is_volatile ( self ):
+      return self.volatile is not None
+   # --- end of is_volatile (...) ---
+
+   def is_persistent ( self ):
+      return self.volatile is None
+   # --- end of is_persistent (...) ---
+
+   def make_volatile ( self, p_info, backref=None ):
+      self.volatile = p_info.get_ref()
+      self.sha256   = None
+      if backref is not None:
+         self.add_backref ( backref )
+      return self
+   # --- end of make_volatile (...) ---
+
+   def make_persistent ( self ):
+      p_info        = self.volatile.deref_safe()
+      self.sha256   = p_info.make_distmap_hash()
+      self.volatile = None
+      return self
+   # --- end of make_persistent (...) ---
+
+   def deref_volatile ( self ):
+      return None if self.volatile is None else self.volatile.deref_unsafe()
+   # --- end of deref_volatile (...) ---
+
    #def add_backref ( self, ref ): self.backrefs.add ( ref )
 
    def has_backref_to ( self, obj ):
@@ -127,7 +158,7 @@ class DistMapInfo ( object ):
       * field_delimiter -- char (or char sequence) that is used to separate
                            values
       """
-      assert not self.volatile
+      assert self.volatile is None
       return ( field_delimiter.join ((
          distfile,
          self.repo_name,
@@ -212,13 +243,13 @@ class _DistMapBase ( object ):
 
    def _iter_persistent ( self ):
       for distfile, info in self._distmap.items():
-         if not info.volatile:
+         if info.is_persistent():
             yield ( distfile, info )
    # --- end of _iter_persistent (...) ---
 
    def _iter_volatile ( self ):
       for distfile, info in self._distmap.items():
-         if info.volatile:
+         if info.is_volatile():
             yield ( distfile, info )
    # --- end of _iter_volatile (...) ---
 
@@ -244,7 +275,7 @@ class _DistMapBase ( object ):
 
    def gen_info_lines ( self, field_delimiter ):
       for distfile, info in self._distmap.items():
-         if not info.volatile:
+         if info.is_persistent():
             yield info.to_str ( str ( distfile ), field_delimiter )
    # --- end of gen_info_lines (...) ---
 
@@ -262,9 +293,15 @@ class _DistMapBase ( object ):
          # entry exists and belongs to backref, nothing to do here
          # a revbump check might be necessary
          return 2
-      else:
+      elif entry.has_backrefs():
          # collision, should be resolved by the distroot
          return 0
+      else:
+         # distfile has no owner
+         #  verify <>.repo, ...
+         #
+         entry.add_backref ( package_dir.get_ref() )
+         return 3
    # --- end of get_distfile_slot (...) ---
 
    def check_revbump_necessary ( self, package_info ):
@@ -437,12 +474,34 @@ class _DistMapBase ( object ):
 
       Returns: created entry
       """
-      return self.add_entry (
-         p_info.get_distmap_key(),
-         DistMapInfo.from_package_info ( p_info )
-      )
+      distfile = p_info.get_distmap_key()
+      entry    = self._distmap.get ( entry, None )
+
+      if entry is None or entry.deref_volatile() is not p_info:
+         return self.add_entry (
+            p_info.get_distmap_key(),
+            DistMapInfo.from_package_info ( p_info )
+         )
+      else:
+         entry.make_persistent()
+         self._file_added ( distfile )
+         return entry
    # --- end of add_entry_for (...) ---
 
+   def add_entry_for_volatile ( self, p_info ):
+      distfile = p_info.get_distmap_key()
+      entry    = self._distmap [distfile]
+
+      if entry.deref_volatile() is p_info:
+         entry.make_persistent()
+         self._file_added ( distfile )
+         return entry
+      else:
+         raise DistmapException (
+            "volatile entry for {} does not exist!".format ( distfile )
+         )
+   # --- end of add_entry_for_volatile (...) ---
+
    def add_dummy_entry (
       self, distfile, distfilepath=None, hashdict=None, log_level=None
    ):
@@ -599,7 +658,7 @@ class FileDistMap ( _DistMapBase ):
 
    def gen_info_lines ( self ):
       for distfile, info in self._distmap.items():
-         if not info.volatile:
+         if info.is_persistent():
             yield info.to_str ( str ( distfile ), self.FIELD_DELIMITER )
    # --- end of gen_info_lines (...) ---
 


             reply	other threads:[~2013-09-03 12:21 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-03 12:21 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-07-07  4:19 [gentoo-commits] proj/R_overlay:master commit in: roverlay/db/ Benda XU
2014-07-16 15:14 André Erdmann
2013-09-05 14:43 André Erdmann
2013-09-05 14:43 André Erdmann
2013-09-05 14:43 André Erdmann
2013-09-05 10:24 André Erdmann
2013-09-05  9:25 André Erdmann
2013-09-05  9:25 André Erdmann
2013-09-05  9:25 André Erdmann
2013-09-03 15:37 André Erdmann
2013-09-03 13:15 André Erdmann
2013-09-03 12:21 André Erdmann
2013-09-02  8:44 André Erdmann
2013-08-30 15:25 André Erdmann
2013-08-30 15:23 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-22  9:01 André Erdmann
2013-08-16 14:26 André Erdmann
2013-08-16 12:42 André Erdmann
2013-08-15  9:18 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-13  8:56 André Erdmann
2013-07-30 18:40 André Erdmann
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-10 16:16 ` [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

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=1378210682.924bba0dca52503b87a73ce386c01bf33e2fa008.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