public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/actions/
@ 2013-06-13 16:34 André Erdmann
  0 siblings, 0 replies; 4+ messages in thread
From: André Erdmann @ 2013-06-13 16:34 UTC (permalink / raw
  To: gentoo-commits

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 ---


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/actions/
@ 2013-06-13 16:34 André Erdmann
  0 siblings, 0 replies; 4+ messages in thread
From: André Erdmann @ 2013-06-13 16:34 UTC (permalink / raw
  To: gentoo-commits

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

package rules, actions: modify package information

The "info" modules provides rather abstract classes for modifying the info dict
of a PackageInfo instance, either by simply adding key=value to it (thereby
overwriting the previous value) or by manipulating an existing value with a
regex.

Note: PackageInfo does not support these actions yet (it will ignore them)

---
 roverlay/packagerules/actions/info.py     | 170 ++++++++++++++++++++++++++++++
 roverlay/packagerules/actions/relocate.py |  37 +++++++
 2 files changed, 207 insertions(+)

diff --git a/roverlay/packagerules/actions/info.py b/roverlay/packagerules/actions/info.py
new file mode 100644
index 0000000..538fdef
--- /dev/null
+++ b/roverlay/packagerules/actions/info.py
@@ -0,0 +1,170 @@
+# R overlay -- package rule actions, modify package information
+# -*- 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__ = [
+   'InfoRenameAction', 'LazyInfoRenameAction', 'SuperLazyInfoRenameAction',
+   'InfoSetToAction',
+]
+
+import re
+
+import roverlay.packagerules.actions.attach
+import roverlay.packagerules.abstract.actions
+
+
+class InfoRenameAction (
+   roverlay.packagerules.abstract.actions.PackageRuleAction
+):
+   """A rename action modifies a package's info using regular expressions."""
+
+   def __init__ ( self, key, regex, subst, priority=1000 ):
+      """Constructor for InfoRenameAction.
+
+      arguments:
+      * key      -- info key that should be modified
+      * regex    -- regex for matching a part of the original value
+                     (using re.search())
+      * subst    -- replacement for the matched value part
+      * priority --
+      """
+      super ( InfoRenameAction, self ).__init__ ( priority=priority )
+
+      self.key   = key
+      self.regex = (
+         re.compile ( regex ) if isinstance ( regex, str ) else regex
+      )
+      self.subst = subst
+   # --- end of __init__ (...) ---
+
+   def re_sub ( self, value ):
+      # count? flags?
+      return self.regex.sub ( self.subst, value )
+   # --- end of re_sub (...) ---
+
+   def apply_action ( self, p_info ):
+      """Sets
+      p_info [<stored key>] = <original value modified by stored regex,subst>
+
+      arguments:
+      * p_info --
+      """
+      # this only works for keys known _before_ reading desc data
+      p_info.set_direct_unsafe ( self.key, self.re_sub ( p_info [self.key] ) )
+   # --- end of apply_action (...) ---
+
+   def gen_str ( self, level ):
+      # FIXME: that's not always correct!
+      # (could be solved by storing the original regex delimiter)
+      yield (
+         level * '   ' + 'rename ' + self.key
+         + ' s/' + self.regex.pattern + '/' + self.subst + '/' # + flags
+      )
+   # --- end of gen_str (...) ---
+
+# --- end of InfoRenameAction ---
+
+
+class InfoRenameOtherAction ( InfoRenameAction ):
+   """Like InfoRenameAction,
+   but uses a second key for retrieving the original value.
+   """
+
+   def __init__ ( self, key, src_key, dest_key, regex, subst, priority=1000 ):
+      super ( InfoRenameOtherAction, self ).__init__ (
+         key=key, regex=regex, subst=subst, priority=priority
+      )
+      # note that key is only used in gen_str()
+      self.src_key  = src_key
+      self.dest_key = dest_key
+   # --- end of __init__ (...) ---
+
+   def apply_action ( self, p_info ):
+      orig_value = p_info [self.src_key]
+      p_info.set_direct_unsafe (
+         self.dest_key, self.re_sub ( p_info [self.src_key] )
+      )
+   # --- end of apply_action (...) ---
+
+# --- end of InfoRenameOtherAction ---
+
+
+class LazyInfoRenameAction (
+   roverlay.packagerules.actions.attach.LazyAction
+):
+   """A lazy variant of InfoRenameAction."""
+   def __init__ ( self, key, regex, subst, priority=1000 ):
+      super ( LazyInfoRenameAction, self ).__init__ (
+         InfoRenameAction ( key=key, regex=regex, subst=subst, priority=None ),
+         priority=priority
+      )
+
+      # or use self._action.key (but self.key should point to the same object)
+      self.key = key
+   # --- end of __init__ (...) ---
+
+   def can_apply_action ( self, p_info ):
+      return p_info.has_key ( self.key )
+   # --- end of can_apply_action (...) ---
+
+# --- end of LazyInfoRenameAction ---
+
+
+class SuperLazyInfoRenameAction (
+   roverlay.packagerules.actions.attach.SuperLazyAction
+):
+   """A super lazy variant of InfoRenameAction."""
+
+   # alternatively use multi-inheritance in [Super]Lazy<modify type>InfoAction
+
+   def __init__ ( self, key, regex, subst, priority=1000 ):
+      super ( SuperLazyInfoRenameAction, self ).__init__ (
+         InfoRenameAction ( key=key, regex=regex, subst=subst, priority=None ),
+         priority=priority
+      )
+      self.key = key
+   # --- end of __init__ (...) ---
+
+   def can_apply_action ( self, p_info ):
+      return p_info.has_key ( self.key )
+   # --- end of can_apply_action (...) ---
+
+# --- end of SuperLazyInfoRenameAction ---
+
+
+class InfoSetToAction (
+   roverlay.packagerules.abstract.actions.PackageRuleAction
+):
+   """A set-to action simply sets a package's info."""
+
+   def __init__ ( self, key, value, priority=1000 ):
+      """Constructor for InfoSetToAction.
+
+      arguments:
+      * key      -- info key that should be modified
+      * value    -- value that will be stored
+      * priority --
+      """
+      super ( InfoSetToAction, self ).__init__ ( priority=priority )
+      self.key   = key
+      self.value = value
+   # --- end of __init__ (...) ---
+
+   def apply_action ( self, p_info ):
+      """Sets p_info [<stored key>] = <stored value>.
+
+      arguments:
+      * p_info --
+      """
+      p_info.set_direct_unsafe ( self.key, self.value )
+   # --- end of apply_action (...) ---
+
+   def gen_str ( self, level ):
+      yield ( level * '   ' + 'set ' + self.key + ' ' + self.value )
+   # --- end of gen_str (...) ---
+
+# --- end of InfoSetToAction ---
+
+# no lazy variants of InfoSetToAction - it should always be applied directly

diff --git a/roverlay/packagerules/actions/relocate.py b/roverlay/packagerules/actions/relocate.py
new file mode 100644
index 0000000..52e3281
--- /dev/null
+++ b/roverlay/packagerules/actions/relocate.py
@@ -0,0 +1,37 @@
+# R overlay -- package rule actions, specific classes for modifing pkg info
+# -*- 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 os.path
+
+import roverlay.packagerules.actions.info
+
+# FIXME: rename module?
+
+class SrcDestRenameAction (
+   roverlay.packagerules.actions.info.InfoRenameOtherAction
+):
+
+   def __init__ ( self, key, regex, subst, priority=1000 ):
+      super ( SrcDestRenameAction, self ).__init__ (
+         key=key, src_key="package_filename",
+         dest_key="src_uri_dest", regex=regex, subst=subst, priority=priority
+      )
+   # --- end of __init__ (...) ---
+
+   def apply_action ( self, p_info ):
+      # don't modify the ".tar.gz" file extension
+      #  TODO: other f-exts will be replaced, this is not critical, because:
+      #  * all R packages end with .tar.gz
+      #  * fext is an empty str if orig_value does not end with .tar.gz,
+      #     so combining fname and fext does not break anything
+      #  => worst case is "more accurate regex required" (+overhead here)
+      #
+      fname, fext, DONT_CARE = p_info [self.src_key].partition ( ".tar.gz" )
+
+      p_info.set_direct_unsafe ( self.dest_key, self.re_sub ( fname ) + fext )
+   # --- end of apply_action (...) ---
+
+# --- end of SrcDestRenameAction (...) ---


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/actions/
@ 2013-08-23 13:52 André Erdmann
  0 siblings, 0 replies; 4+ messages in thread
From: André Erdmann @ 2013-08-23 13:52 UTC (permalink / raw
  To: gentoo-commits

commit:     52a22dadbfee70229a45447f2ac926cec7405edd
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 23 13:40:15 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 23 13:40:15 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=52a22dad

package rules, dep actions: use ConstantDepResult

Create dep result objects when injecting deps.

---
 roverlay/packagerules/actions/dependencies.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/roverlay/packagerules/actions/dependencies.py b/roverlay/packagerules/actions/dependencies.py
index 39a002c..5e597e2 100644
--- a/roverlay/packagerules/actions/dependencies.py
+++ b/roverlay/packagerules/actions/dependencies.py
@@ -4,12 +4,14 @@
 # Distributed under the terms of the GNU General Public License;
 # either version 2 of the License, or (at your option) any later version.
 
-import roverlay.packagerules.abstract.actions
-
 import roverlay.util.dictwalk
 import roverlay.util.namespace
 import roverlay.util.objects
 
+import roverlay.depres.depresult
+
+import roverlay.packagerules.abstract.actions
+
 
 
 class DepConfAccess ( roverlay.util.dictwalk.FixedKeyDictWalker ):
@@ -76,16 +78,25 @@ class DependencyAction (
 class DependencyVarAction ( DependencyAction ):
 
    CATEGORY_KEY = None
+   CONVERT_VALUE_TO_DEPRESULT = True
 
    @classmethod
-   def from_namespace ( cls, namespace, deptype_key, *args, **kwargs ):
+   def from_namespace ( cls, namespace, deptype_key, value, *args, **kwargs ):
       assert cls.CATEGORY_KEY is not None
 
       depconf_access = namespace.get_object (
          DepConfAccess, ( cls.CATEGORY_KEY, deptype_key )
       )
+
+      if cls.CONVERT_VALUE_TO_DEPRESULT:
+         my_value = namespace.get_object_v (
+            roverlay.depres.depresult.ConstantDepResult, ( value, 50, 0 )
+         )
+      else:
+         my_value = value
+
       return namespace.get_object_v (
-         cls, ( depconf_access, ) + args, kwargs
+         cls, ( depconf_access, my_value ) + args, kwargs
       )
    # --- end of from_namespace (...) ---
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/actions/
@ 2013-09-05 16:01 André Erdmann
  0 siblings, 0 replies; 4+ messages in thread
From: André Erdmann @ 2013-09-05 16:01 UTC (permalink / raw
  To: gentoo-commits

commit:     4a088d3c85e009f005d1b37b2eaf5423583f9326
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Sep  5 15:53:39 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Sep  5 15:53:39 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=4a088d3c

fix LicenseEvarAction

---
 roverlay/packagerules/actions/evar.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/roverlay/packagerules/actions/evar.py b/roverlay/packagerules/actions/evar.py
index ea9d9f2..1b03bb2 100644
--- a/roverlay/packagerules/actions/evar.py
+++ b/roverlay/packagerules/actions/evar.py
@@ -78,7 +78,7 @@ class KeywordsEvarAction ( EvarWithValueAction ):
 
 # --- end of KeywordsEvarAction ---
 
-class LicenseEvarAction ( EvarAction ):
+class LicenseEvarAction ( EvarWithValueAction ):
    """A LicenseEvarAction adds a LICENSE=... variable to a PackageInfo."""
 
    EVAR_CLS = roverlay.ebuild.evars.LICENSE


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-05 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-05 16:01 [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/actions/ André Erdmann
  -- strict thread matches above, loose matches on Subject: below --
2013-08-23 13:52 André Erdmann
2013-06-13 16:34 André Erdmann
2013-06-13 16:34 André Erdmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox