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/packagerules/actions/
Date: Thu, 13 Jun 2013 16:34:26 +0000 (UTC)	[thread overview]
Message-ID: <1370378508.9a3e68c735ae1caa084dba046e2f317ea85f1d13.dywi@gentoo> (raw)

commit:     9a3e68c735ae1caa084dba046e2f317ea85f1d13
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jun  4 20:41:48 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jun  4 20:41:48 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9a3e68c7

package rules, actions/attach: lazy actions!

Some actions cannot be applied when apply_action() is called. So-called "lazy"
actions attach themselves to a PackageInfo instance. Afterwards, the pkg info
has to take care about applying the action as soon as enough data (info dict)
is available.

Super lazy actions will try to apply an action directly before attaching
themselves to a package. Don't use them unless you really don't care when (and
if!) an action should be applied.

PackageInfo currently lacks support for lazy actions, so trying to use them
results in runtime exceptions (NotImplementedError).

---
 roverlay/packagerules/actions/attach.py | 85 +++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/roverlay/packagerules/actions/attach.py b/roverlay/packagerules/actions/attach.py
new file mode 100644
index 0000000..e70c8cb
--- /dev/null
+++ b/roverlay/packagerules/actions/attach.py
@@ -0,0 +1,85 @@
+# R overlay -- package rule actions, "lazy" actions
+# -*- 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.
+
+__all__ = [ 'LazyAction', 'SuperLazyAction', ]
+
+
+import roverlay.packagerules.abstract.actions
+
+
+class LazyAction ( roverlay.packagerules.abstract.actions.PackageRuleAction ):
+   """A lazy action simply adds an action to a PackageInfo object.
+   The action can then be applied later on (initiated by the pkg info).
+
+   Note that this cannot be used to filter out packages.
+   """
+
+   def __init__ ( self, actual_action, priority=1000 ):
+      """Constructor for LazyAction.
+
+      arguments:
+      * actual_action -- object implementing at least apply_action(^1).
+      * priority      --
+      """
+      super ( LazyAction, self ).__init__ ( priority=priority )
+      self._action = actual_action
+   # --- end of __init__ (...) ---
+
+   def can_apply_action ( self, p_info ):
+      """Returns True if the stored action can be applied to p_info,
+      else False.
+      """
+      raise NotImplementedError ( "derived classes have to implement this." )
+   # --- end of can_apply_action (...) ---
+
+   def apply_action ( self, p_info ):
+      """Attaches this action to p_info's lazy actions.
+
+      arguments:
+      * p_info
+      """
+      p_info.attach_lazy_action ( self )
+   # --- end of apply_action (...) ---
+
+   def try_apply_action ( self, p_info ):
+      """Tries to apply the stored action.
+
+      Returns True if the action could be applied (action condition evaluated
+      to True), else False.
+
+      Make sure to remove this action from p_info once it has been applied.
+
+      arguments:
+      * p_info --
+      """
+      if self.can_apply_action ( p_info ):
+         if self._action.apply_action ( p_info ) is False:
+            raise RuntimeError ( "lazy actions cannot filter out packages." )
+         else:
+            return True
+      else:
+         return False
+   # --- end of try_apply_action (...) ---
+
+   def gen_str ( self, level ):
+      for s in self._action.gen_str ( level ): yield s
+   # --- end of gen_str (...) ---
+
+# --- end of LazyAction ---
+
+
+class SuperLazyAction ( LazyAction ):
+   """Like LazyAction, but tries to apply the action before attaching it.
+   Useful if it's unknown whether an action can be applied a PackageInfo
+   instance directly or not, costs one more check per package if it cannot
+   be applied directly."""
+
+   def apply_action ( self, p_info ):
+      if not self.try_apply_action ( p_info ):
+         p_info.attach_lazy_action ( self )
+   # --- end of apply_action (...) ---
+
+# --- end of SuperLazyAction ---


             reply	other threads:[~2013-06-13 16:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-13 16:34 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-06-13 16:34 [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/actions/ André Erdmann
2013-08-23 13:52 André Erdmann
2013-09-05 16:01 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=1370378508.9a3e68c735ae1caa084dba046e2f317ea85f1d13.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