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

commit:     522bb1743f77e63922d32abb21e7016c6fea0e0e
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Apr 23 00:42:21 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Apr 23 00:42:21 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=522bb174

Package Rules: 'trace' action

The 'trace' action can be used to track changes done by package rules.

It has to implementations (action classes), depending on whether an arg is
supplied in the rule file or not:

* TraceAction (with arg), which adds the arg (typically a string) to a
  package's modified_by_package_rules variable when apply_action() is called

* MarkAsModifiedAction (without arg), which simply sets the
  modified_by_package_rules variable to True if it isn't already set.

Note that this is a testing/debugging feature and that there's currently no
(simple) method to access the trace variable.

---
 roverlay/packagerules/actions/trace.py         |   61 ++++++++++++++++++++++++
 roverlay/packagerules/parser/context/action.py |   39 ++++++++++++---
 2 files changed, 92 insertions(+), 8 deletions(-)

diff --git a/roverlay/packagerules/actions/trace.py b/roverlay/packagerules/actions/trace.py
new file mode 100644
index 0000000..0b1cc30
--- /dev/null
+++ b/roverlay/packagerules/actions/trace.py
@@ -0,0 +1,61 @@
+# R overlay -- package rule actions, mark packages as modified
+# -*- 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 roverlay.packagerules.abstract.actions
+
+class TraceAction (
+	roverlay.packagerules.abstract.actions.PackageRuleAction
+):
+	"""Assigns a specific value (identifier) to the modified_by_package_rules
+	variable of a PackageInfo object.
+	"""
+
+	def __init__ ( self, trace_ident, priority=1000, _append=True ):
+		super ( TraceAction, self ).__init__ ( priority=priority )
+		self._ident  = trace_ident
+		self._append = _append
+	# --- end of __init__ (...) ---
+
+	def apply_action ( self, p_info ):
+		if self._append:
+			if hasattr ( p_info, 'modified_by_package_rules' ):
+				if (
+					hasattr ( p_info.modified_by_package_rules, '__iter__' )
+					and not isinstance ( p_info.modified_by_package_rules, str )
+				):
+					p_info.modified_by_package_rules.append ( self._ident )
+				else:
+					p_info.modified_by_package_rules = [
+						p_info.modified_by_package_rules, self._ident
+					]
+			else:
+				p_info.modified_by_package_rules = [ self._ident ]
+		else:
+			p_info.modified_by_package_rules = self._ident
+	# --- end of apply_action (...) ---
+
+	def gen_str ( self, level ):
+		yield ( level * '   ' ) + "trace " + str ( self._ident )
+	# --- end of gen_str (...) ---
+
+
+class MarkAsModifiedAction (
+	roverlay.packagerules.abstract.actions.PackageRuleAction
+):
+	"""Simply marks a PackageInfo object as modified."""
+
+	def apply_action ( self, p_info ):
+		"""Marks a package as modified."""
+		if (
+			not hasattr ( p_info, 'modified_by_package_rules' )
+			or not p_info.modified_by_package_rules
+		):
+			p_info.modified_by_package_rules = True
+	# --- end of apply_action (...) ---
+
+	def gen_str ( self, level ):
+		yield ( level * '   ' ) + "trace"
+	# --- end of gen_str (...) ---

diff --git a/roverlay/packagerules/parser/context/action.py b/roverlay/packagerules/parser/context/action.py
index ff5876c..566cb67 100644
--- a/roverlay/packagerules/parser/context/action.py
+++ b/roverlay/packagerules/parser/context/action.py
@@ -7,6 +7,7 @@
 import roverlay.strutil
 
 import roverlay.packagerules.actions.evar
+import roverlay.packagerules.actions.trace
 import roverlay.packagerules.parser.context.base
 
 class ActionUnknown ( ValueError ):
@@ -29,6 +30,10 @@ class RuleActionContext (
 		'do-not-process'
 	))
 
+	KEYWORDS_ACTION_TRACE = frozenset ((
+		'trace',
+	))
+
 	# dict ( <keyword> => <evar class> )
 	# Dict of evar action keywords (with corresponding classes)
 	#
@@ -66,22 +71,40 @@ class RuleActionContext (
 			# split _str into (<keyword>,<value>)
 			argv = roverlay.strutil.split_whitespace ( _str, maxsplit=1 )
 
-			evar_cls = self.KEYWORDS_EVAR.get ( argv [0], None )
-
-			try:
-				if evar_cls:
+			if argv [0] in self.KEYWORDS_ACTION_TRACE:
+				if len ( argv ) > 1 and argv [1]:
 					self._actions.append (
 						self.namespace.get_object (
-							evar_cls,
+							roverlay.packagerules.actions.trace.TraceAction,
 							roverlay.strutil.unquote ( argv [1] ),
 							lino
 						)
 					)
 				else:
-					raise ActionUnknown ( _str )
+					self._actions.append (
+						self.namespace.get_object (
+							roverlay.packagerules.actions.trace.MarkAsModifiedAction,
+							lino
+						)
+					)
+
+			else:
+				evar_cls = self.KEYWORDS_EVAR.get ( argv [0], None )
+
+				try:
+					if evar_cls:
+						self._actions.append (
+							self.namespace.get_object (
+								evar_cls,
+								roverlay.strutil.unquote ( argv [1] ),
+								lino
+							)
+						)
+					else:
+						raise ActionUnknown ( _str )
 
-			except IndexError:
-				raise ActionNeedsValue ( _str )
+				except IndexError:
+					raise ActionNeedsValue ( _str )
 	# --- end of feed (...) ---
 
 	def create ( self ):


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

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/parser/context/, roverlay/packagerules/actions/
@ 2013-08-19 15:42 André Erdmann
  0 siblings, 0 replies; 6+ messages in thread
From: André Erdmann @ 2013-08-19 15:42 UTC (permalink / raw
  To: gentoo-commits

commit:     550c170f8a2bb74d053ab34acfac980b6e7b92a8
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Aug 19 15:36:27 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Aug 19 15:36:27 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=550c170f

package rules: support variables, "rename" category

* "set destfile" fixed (previously wrote do the 'destfile' info key, which is
   not used by roverlay -- effectively did nothing)
* "set" actions support variable substitution now, _selftest() ensures that
   only a certain set of info keys is accessible
* the category can now be renamed. Basically, this renames the repo name and
   writes the result to "category".

---
 roverlay/packagerules/actions/info.py          | 120 +++++++++++++++++++------
 roverlay/packagerules/actions/relocate.py      |  44 +++++++--
 roverlay/packagerules/parser/context/action.py |   7 +-
 3 files changed, 133 insertions(+), 38 deletions(-)

diff --git a/roverlay/packagerules/actions/info.py b/roverlay/packagerules/actions/info.py
index d9f1390..9251856 100644
--- a/roverlay/packagerules/actions/info.py
+++ b/roverlay/packagerules/actions/info.py
@@ -10,17 +10,60 @@ __all__ = [
 ]
 
 import re
+import string
 
 import roverlay.packagerules.actions.attach
 import roverlay.packagerules.abstract.actions
 
 
-class InfoRenameAction (
+class InfoManipulatingAction (
    roverlay.packagerules.abstract.actions.PackageRuleAction
 ):
+   FORMATTER    = string.Formatter()
+   DEFAULT_VARS = dict.fromkeys (
+      {
+         'repo_name', 'version', 'package_name', 'name',
+         'package_filename',
+      },
+      "U"
+   )
+
+   def __init__ ( self, key, priority=None ):
+      super ( InfoManipulatingAction, self ).__init__ (
+         priority=( 1000 if priority is None else priority )
+      )
+      self.key = key
+   # --- end of __init__ (...) ---
+
+   @classmethod
+   def try_format ( cls, text, kwargs=None ):
+      try:
+         cls.FORMATTER.vformat (
+            text, (), ( cls.DEFAULT_VARS if kwargs is None else kwargs )
+         )
+      except ( IndexError, KeyError, AttributeError ):
+         return False
+      else:
+         return True
+   # --- end of try_format (...) ---
+
+   @classmethod
+   def needs_formatter ( cls, text ):
+      for literal_text, field_name, format_spec, conversion in (
+         cls.FORMATTER.parse ( text )
+      ):
+         return bool ( field_name is not None )
+      else:
+         return False
+   # --- end of needs_formatter (...) ---
+
+# --- end of InfoManipulatingAction ---
+
+
+class InfoRenameAction ( InfoManipulatingAction ):
    """A rename action modifies a package's info using regular expressions."""
 
-   def __init__ ( self, key, regex, subst, priority=1000 ):
+   def __init__ ( self, key, regex, subst, priority=None ):
       """Constructor for InfoRenameAction.
 
       arguments:
@@ -30,9 +73,8 @@ class InfoRenameAction (
       * subst    -- replacement for the matched value part
       * priority --
       """
-      super ( InfoRenameAction, self ).__init__ ( priority=priority )
+      super ( InfoRenameAction, self ).__init__ ( key=key, priority=priority )
 
-      self.key   = key
       self.regex = (
          re.compile ( regex ) if isinstance ( regex, str ) else regex
       )
@@ -69,23 +111,14 @@ class InfoRenameAction (
 
 class InfoRenameOtherAction ( InfoRenameAction ):
    """Like InfoRenameAction,
-   but uses a second key for retrieving the original value.
+   but uses a pair of keys for setting/retrieving the actual 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__ (...) ---
+   DEST_KEY = None
+   SRC_KEY  = None
 
    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] )
-      )
+      orig_value = p_info [self.SRC_KEY]
+      p_info.set_direct_unsafe ( self.DEST_KEY, self.re_sub ( orig_value ) )
    # --- end of apply_action (...) ---
 
 # --- end of InfoRenameOtherAction ---
@@ -95,9 +128,11 @@ class LazyInfoRenameAction (
    roverlay.packagerules.actions.attach.LazyAction
 ):
    """A lazy variant of InfoRenameAction."""
-   def __init__ ( self, key, regex, subst, priority=1000 ):
+   def __init__ ( self, key, regex, subst, priority=None ):
       super ( LazyInfoRenameAction, self ).__init__ (
-         InfoRenameAction ( key=key, regex=regex, subst=subst, priority=None ),
+         InfoRenameAction (
+            key=key, regex=regex, subst=subst, priority=False
+         ),
          priority=priority
       )
 
@@ -121,7 +156,9 @@ class SuperLazyInfoRenameAction (
 
    def __init__ ( self, key, regex, subst, priority=1000 ):
       super ( SuperLazyInfoRenameAction, self ).__init__ (
-         InfoRenameAction ( key=key, regex=regex, subst=subst, priority=None ),
+         InfoRenameAction (
+            key=key, regex=regex, subst=subst, priority=False
+         ),
          priority=priority
       )
       self.key = key
@@ -134,12 +171,10 @@ class SuperLazyInfoRenameAction (
 # --- end of SuperLazyInfoRenameAction ---
 
 
-class InfoSetToAction (
-   roverlay.packagerules.abstract.actions.PackageRuleAction
-):
+class InfoSetToAction ( InfoManipulatingAction ):
    """A set-to action simply sets a package's info."""
 
-   def __init__ ( self, key, value, priority=1000 ):
+   def __init__ ( self, key, value, priority=None ):
       """Constructor for InfoSetToAction.
 
       arguments:
@@ -147,20 +182,49 @@ class InfoSetToAction (
       * value    -- value that will be stored
       * priority --
       """
-      super ( InfoSetToAction, self ).__init__ ( priority=priority )
-      self.key   = key
+      super ( InfoSetToAction, self ).__init__ ( key=key, priority=priority )
       self.value = value
+
+      # bind apply_action()
+      if self.needs_formatter ( value ):
+         self.apply_action = self.apply_variable_value
+      else:
+         self.apply_action = self.apply_fixed_value
    # --- end of __init__ (...) ---
 
-   def apply_action ( self, p_info ):
+   def apply_fixed_value ( 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_fixed_value (...) ---
+
+   def apply_variable_value ( self, p_info ):
+      """Sets p_info [<stored key>] = <stored value> ~ <p_info._info>.
+
+      arguments:
+      * p_info --
+      """
+      # direct info dict access
+      value = self.FORMATTER.vformat ( self.value, (), p_info._info )
+      p_info.set_direct_unsafe ( self.key, value )
+   # --- end of apply_variable_value (...) ---
+
+   def apply_action ( self, p_info ):
+      """Sets p_info [<stored key>] = <stored value>.
+
+      arguments:
+      * p_info --
+      """
+      raise Exception ( "this method should have been re-bound in __init__." )
    # --- end of apply_action (...) ---
 
+   def _selftest ( self ):
+      return self.try_format ( self.value )
+   # --- end of _selftest (...) ---
+
    def gen_str ( self, level ):
       yield ( level * self.INDENT + 'set ' + self.key + ' ' + self.value )
    # --- end of gen_str (...) ---

diff --git a/roverlay/packagerules/actions/relocate.py b/roverlay/packagerules/actions/relocate.py
index 52e3281..db58b78 100644
--- a/roverlay/packagerules/actions/relocate.py
+++ b/roverlay/packagerules/actions/relocate.py
@@ -10,17 +10,38 @@ import roverlay.packagerules.actions.info
 
 # FIXME: rename module?
 
-class SrcDestRenameAction (
-   roverlay.packagerules.actions.info.InfoRenameOtherAction
+class AliasedInfoSetToAction (
+   roverlay.packagerules.actions.info.InfoSetToAction
 ):
+   DEST_KEY = None
 
-   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
+   def __init__ ( self, action_key, value, priority=None ):
+      super ( AliasedInfoSetToAction, self ).__init__ (
+         key=self.__class__.DEST_KEY, value=value, priority=priority
       )
+      self.action_key = action_key
    # --- end of __init__ (...) ---
 
+   def gen_str ( self, level ):
+      yield (
+         ( level * self.INDENT )
+         + 'set ' + self.action_key + ' ' + self.value
+      )
+   # --- end of gen_str (...) ---
+
+# --- end of AliasedInfoSetToAction ---
+
+
+class SrcDestSetToAction ( AliasedInfoSetToAction ):
+   DEST_KEY = 'src_uri_dest'
+# --- end of SrcDestSetToAction ---
+
+class SrcDestRenameAction (
+   roverlay.packagerules.actions.info.InfoRenameOtherAction
+):
+   SRC_KEY  = 'package_filename'
+   DEST_KEY = 'src_uri_dest'
+
    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:
@@ -29,9 +50,16 @@ class SrcDestRenameAction (
       #     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" )
+      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 )
+      p_info.set_direct_unsafe ( self.DEST_KEY, self.re_sub ( fname ) + fext )
    # --- end of apply_action (...) ---
 
 # --- end of SrcDestRenameAction (...) ---
+
+class CategoryRenameAction (
+   roverlay.packagerules.actions.info.InfoRenameOtherAction
+):
+   SRC_KEY  = 'repo_name'
+   DEST_KEY = 'category'
+# --- end of CategoryRenameAction ---

diff --git a/roverlay/packagerules/parser/context/action.py b/roverlay/packagerules/parser/context/action.py
index 1828754..696ae5b 100644
--- a/roverlay/packagerules/parser/context/action.py
+++ b/roverlay/packagerules/parser/context/action.py
@@ -71,9 +71,12 @@ class RuleActionContext (
    #
    MODIFIABLE_INFO_KEYS = {
       'name'     : None,
-      'category' : ( None, False ),
-      'destfile' : (
+      'category' : (
          None,
+         roverlay.packagerules.actions.relocate.CategoryRenameAction,
+      ),
+      'destfile' : (
+         roverlay.packagerules.actions.relocate.SrcDestSetToAction,
          roverlay.packagerules.actions.relocate.SrcDestRenameAction
       ),
    }


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

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

commit:     e05a07978609ee28f975df861076015aaf985fdd
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 23 11:20:47 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 23 11:20:47 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e05a0797

package rules, add dependency action

Add syntax/actions for rules that add dependencies (to
DEPEND/RDEPEND/RSUGGESTS).

---
 roverlay/packagerules/actions/dependencies.py  | 132 +++++++++++++++++++++++++
 roverlay/packagerules/parser/context/action.py |  64 ++++++++++--
 2 files changed, 188 insertions(+), 8 deletions(-)

diff --git a/roverlay/packagerules/actions/dependencies.py b/roverlay/packagerules/actions/dependencies.py
new file mode 100644
index 0000000..39a002c
--- /dev/null
+++ b/roverlay/packagerules/actions/dependencies.py
@@ -0,0 +1,132 @@
+# R overlay -- package rule actions, modify dependencies / depres
+# -*- 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 roverlay.packagerules.abstract.actions
+
+import roverlay.util.dictwalk
+import roverlay.util.namespace
+import roverlay.util.objects
+
+
+
+class DepConfAccess ( roverlay.util.dictwalk.FixedKeyDictWalker ):
+
+   # ideally, use a data type that
+   # (a) drops duplicates
+   # (b) is ordered
+   DEFAULT_CONTAINER_TYPE = set
+
+   def __init__ ( self, keypath, virtual_key=None ):
+      super ( DepConfAccess, self ).__init__ ( keypath )
+      self.virtual_key = (
+         self.keypath[-1] if virtual_key is None else virtual_key
+      )
+   # --- end of __init__ (...) ---
+
+   def get_root ( self, p_info ):
+      if p_info.depconf is None:
+         p_info.depconf = dict()
+      return p_info.depconf
+   # --- end of get_root (...) ---
+
+# --- end of DepConfAccess ---
+
+
+class DependencyAction (
+   roverlay.packagerules.abstract.actions.PackageRuleAction
+):
+
+   ACTION_KEYWORD = None
+
+   @classmethod
+   def from_namespace ( cls, namespace, keypath, *args, **kwargs ):
+      depconf_access = namespace.get_object ( DepConfAccess, keypath )
+      return namespace.get_object_v (
+         cls, ( depconf_access, ) + args, kwargs
+      )
+   # --- end of from_namespace (...) ---
+
+   def __init__ ( self, depconf_access, priority=1000 ):
+      super ( DependencyAction, self ).__init__ ( priority=priority )
+      self.depconf = depconf_access
+   # --- end of __init__ (...) ---
+
+   def get_action_keyword ( self ):
+      return self.__class__.ACTION_KEYWORD
+   # --- end of get_action_keyword (...) ---
+
+   @roverlay.util.objects.abstractmethod
+   def get_action_arg_str ( self ):
+      pass
+   # --- end of get_action_arg_str (...) ---
+
+   def gen_str ( self, level ):
+      yield (
+         ( level * self.INDENT ) + self.get_action_keyword()
+         + ' ' + str ( self.depconf.virtual_key )
+         + ' \"' + self.get_action_arg_str() + '\"'
+      )
+   # --- end of gen_str (...) ---
+
+# --- end of DependencyAction ---
+
+class DependencyVarAction ( DependencyAction ):
+
+   CATEGORY_KEY = None
+
+   @classmethod
+   def from_namespace ( cls, namespace, deptype_key, *args, **kwargs ):
+      assert cls.CATEGORY_KEY is not None
+
+      depconf_access = namespace.get_object (
+         DepConfAccess, ( cls.CATEGORY_KEY, deptype_key )
+      )
+      return namespace.get_object_v (
+         cls, ( depconf_access, ) + args, kwargs
+      )
+   # --- end of from_namespace (...) ---
+
+#   @classmethod
+#   def get_subclass (
+#      cls, action_keyword, category_key, name=None, doc=None
+#   ):
+#      class NewDependencyVarAction ( cls ):
+#         ACTION_KEYWORDS = action_keyword
+#         CATEGORY_KEY    = category_key
+#      # --- end of NewDependencyVarAction ---
+#
+#      if name is not None:
+#         NewDependencyVarAction.__name__ = name
+#      else:
+#         NewDependencyVarAction.__name__ = 'New' + cls.__name__
+#
+#      if doc is not None:
+#         NewDependencyVarAction.__doc__ = doc
+#
+#      return NewDependencyVarAction
+#   # --- end of get_subclass (...) ---
+
+   def __init__ ( self, depconf_access, value, priority=1000 ):
+      super ( DependencyVarAction, self ).__init__ (
+         depconf_access, priority=priority
+      )
+      self.value = value
+   # --- end of __init__ (...) ---
+
+   def get_action_arg_str ( self ):
+      return str ( self.value )
+   # --- end of get_action_arg_str (...) ---
+
+   def apply_action ( self, p_info ):
+      self.depconf.add_value ( self.value, p_info )
+   # --- end of apply_action (...) ---
+
+# --- end of DependencyVarAction ---
+
+class DependencyInjectAction ( DependencyVarAction ):
+   ACTION_KEYWORD = 'add'
+   CATEGORY_KEY   = 'extra'
+# --- end of DependencyInjectAction (...) ---

diff --git a/roverlay/packagerules/parser/context/action.py b/roverlay/packagerules/parser/context/action.py
index 696ae5b..b81ba1e 100644
--- a/roverlay/packagerules/parser/context/action.py
+++ b/roverlay/packagerules/parser/context/action.py
@@ -8,6 +8,7 @@ import re
 
 import roverlay.strutil
 
+import roverlay.packagerules.actions.dependencies
 import roverlay.packagerules.actions.evar
 import roverlay.packagerules.actions.info
 import roverlay.packagerules.actions.relocate
@@ -60,12 +61,22 @@ class RuleActionContext (
    DEFAULT_MODIFY_INFO_ACTIONS = (
       roverlay.packagerules.actions.info.InfoSetToAction,
       roverlay.packagerules.actions.info.InfoRenameAction,
+      False
    )
 
-   # dict { key => None | ( None|False|SetTo_Action, None|False|Rename_Action )
+   # dict {
+   #    key => None | (
+   #                     None | False | SetTo_Action,
+   #                     None | False | Rename_Action,
+   #                     None | False | Add_Action,
+   #                  )
    #   where None  is "use default action(s)"
    #   and   False is "invalid"/"not supported"
    #
+   # It's not necessary to implement all action types for a key.
+   # Creation for dependency actions is "hardcoded" below, simply add the
+   # base classes (or True for DependencyInjectAction) here.
+   #
    # (see comment in packageinfo.py concerning keys that exist when calling
    #  apply_action() and enable lazy actions if necessary)
    #
@@ -74,13 +85,25 @@ class RuleActionContext (
       'category' : (
          None,
          roverlay.packagerules.actions.relocate.CategoryRenameAction,
+         False,
       ),
       'destfile' : (
          roverlay.packagerules.actions.relocate.SrcDestSetToAction,
-         roverlay.packagerules.actions.relocate.SrcDestRenameAction
+         roverlay.packagerules.actions.relocate.SrcDestRenameAction,
+         False,
       ),
+      'depend'    : ( False, False, True ),
+      'rdepend'   : ( False, False, True ),
+      'rsuggests' : ( False, False, True ),
    }
 
+   # lowercase here
+   DEPTYPE_KEYS = frozenset ({ 'depend', 'rdepend', 'rsuggests' })
+
+   DEFAULT_DEPENDENCY_ADD_ACTION = (
+      roverlay.packagerules.actions.dependencies.DependencyInjectAction
+   )
+
    # TODO / Notes:
    #
    # * "combined" actions, e.g. name,category as "pseudo" actions?
@@ -102,11 +125,13 @@ class RuleActionContext (
    # --- end of _add_action (...) ---
 
    def _add_as_info_action ( self, keyword, argstr, orig_str, lino ):
-      """Tries to add <keyword, argstr> as package info-manipulating action.
+      """Tries to add <keyword, argstr> as package info or depconf
+      manipulating action.
 
       Returns true if such an action has been created and added, else False.
       Invalid values/lines will be catched here. A return value of False
-      simply means that keyword/argstr do not represent an info action.
+      simply means that keyword/argstr do not represent a depconf or info
+      action.
 
       arguments:
       * keyword  --
@@ -128,6 +153,9 @@ class RuleActionContext (
       elif action_type_str == "rename":
          # is a rename info action, continue
          action_type = 1
+      elif action_type_str == "add":
+         # is a add action, continue
+         action_type = 2
       else:
          # not an info action
          return False
@@ -165,14 +193,34 @@ class RuleActionContext (
 
          if action_cls is None:
             action_cls = self.DEFAULT_MODIFY_INFO_ACTIONS [action_type]
-      except KeyError:
+      except ( KeyError, IndexError ):
          raise ActionUnknown ( orig_str )
 
       # create and add action
       if action_cls is False:
          raise ActionInvalid ( orig_str )
-      elif action_type == 0:
-         # info action (1 arg)
+      elif key in self.DEPTYPE_KEYS:
+         # needs special handling
+         if action_type == 2:
+            if action_cls is True:
+               action_cls = self.DEFAULT_DEPENDENCY_ADD_ACTION
+
+            self._add_action (
+               action_cls.from_namespace (
+                  self.namespace, key.upper(),
+                  roverlay.strutil.unquote ( value )
+               )
+            )
+         else:
+            # unreachable
+            raise NotImplementedError ( orig_str )
+
+      elif action_cls is True:
+         # needs special handling (unreachable for now)
+         raise NotImplementedError ( orig_str )
+
+      elif action_type != 1:
+         # info set/add action (1 arg)
          value = roverlay.strutil.unquote ( value )
 
          if value:
@@ -267,7 +315,7 @@ class RuleActionContext (
                )
 
          elif len ( argv ) > 1 and (
-            self._add_as_info_action ( argv [0], argv [1], _str, lino )
+            self._add_as_info_action ( argv[0], argv[1], _str, lino )
          ):
             pass
 


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

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/parser/context/, roverlay/packagerules/actions/
@ 2013-08-28  9:38 André Erdmann
  0 siblings, 0 replies; 6+ messages in thread
From: André Erdmann @ 2013-08-28  9:38 UTC (permalink / raw
  To: gentoo-commits

commit:     13bb5f5b4ee3c40bb76c622e1b28b9c158f6b1c3
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 28 08:26:32 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 28 08:26:32 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=13bb5f5b

package rule parser: depstr_ignore

This commit adds syntax/parser-side support for ignoring dependency strings on a
per-package level (or group of packages).

---
 roverlay/packagerules/actions/dependencies.py  | 34 ++++++++++++--
 roverlay/packagerules/parser/context/action.py | 64 ++++++++++++++++++++------
 2 files changed, 79 insertions(+), 19 deletions(-)

diff --git a/roverlay/packagerules/actions/dependencies.py b/roverlay/packagerules/actions/dependencies.py
index 5e597e2..db4671d 100644
--- a/roverlay/packagerules/actions/dependencies.py
+++ b/roverlay/packagerules/actions/dependencies.py
@@ -60,16 +60,36 @@ class DependencyAction (
       return self.__class__.ACTION_KEYWORD
    # --- end of get_action_keyword (...) ---
 
+   def get_virtual_key ( self ):
+      key = str ( self.depconf.virtual_key )
+      return None if key == 'all' else key
+   # --- end of get_virtual_key (...) ---
+
    @roverlay.util.objects.abstractmethod
    def get_action_arg_str ( self ):
       pass
    # --- end of get_action_arg_str (...) ---
 
    def gen_str ( self, level ):
-      yield (
-         ( level * self.INDENT ) + self.get_action_keyword()
-         + ' ' + str ( self.depconf.virtual_key )
-         + ' \"' + self.get_action_arg_str() + '\"'
+      action_keyword = self.get_action_keyword()
+      action_arg_str = self.get_action_arg_str()
+      virtual_key    = self.get_virtual_key()
+      indent         = level * self.INDENT
+
+
+      if virtual_key:
+         virtual_key = ' ' + virtual_key
+      else:
+         virtual_key = ''
+
+      if action_arg_str:
+         action_arg_str = ' \"' + action_arg_str + '\"'
+      else:
+         action_arg_str = ''
+
+      yield "{indent}{action_keyword}{virtual_key}{action_arg_str}".format (
+         indent=indent, action_keyword=action_keyword,
+         virtual_key=virtual_key, action_arg_str=action_arg_str
       )
    # --- end of gen_str (...) ---
 
@@ -141,3 +161,9 @@ class DependencyInjectAction ( DependencyVarAction ):
    ACTION_KEYWORD = 'add'
    CATEGORY_KEY   = 'extra'
 # --- end of DependencyInjectAction (...) ---
+
+class DepStrIgnoreAction ( DependencyVarAction ):
+   CATEGORY_KEY   = 'depres_ignore'
+   ACTION_KEYWORD = CATEGORY_KEY
+   CONVERT_VALUE_TO_DEPRESULT = False
+# --- end of DepStrIgnoreAction ---

diff --git a/roverlay/packagerules/parser/context/action.py b/roverlay/packagerules/parser/context/action.py
index b81ba1e..284d62e 100644
--- a/roverlay/packagerules/parser/context/action.py
+++ b/roverlay/packagerules/parser/context/action.py
@@ -55,6 +55,17 @@ class RuleActionContext (
       'keywords' : roverlay.packagerules.actions.evar.KeywordsEvarAction,
    }
 
+   # dict ( <keyword> => <depstr action> )
+   #
+   KEYWORDS_DEPSTR = {
+      'depstr_ignore': (
+         roverlay.packagerules.actions.dependencies.DepStrIgnoreAction
+      ),
+      'depres_ignore': (
+         roverlay.packagerules.actions.dependencies.DepStrIgnoreAction
+      ),
+   }
+
    # default info set-to/rename actions
    #  using the lazy variant for renaming
    #
@@ -208,7 +219,7 @@ class RuleActionContext (
             self._add_action (
                action_cls.from_namespace (
                   self.namespace, key.upper(),
-                  roverlay.strutil.unquote ( value )
+                  roverlay.strutil.unquote ( value ), lino
                )
             )
          else:
@@ -272,6 +283,38 @@ class RuleActionContext (
       return True
    # --- end of _add_as_info_action (...) ---
 
+   def _add_as_keyworded_action ( self, keyword, argstr, orig_str, lino ):
+      if not argstr:
+         raise ActionNeedsValue ( orig_str )
+
+      elif keyword in self.KEYWORDS_EVAR:
+         evar_cls = self.KEYWORDS_EVAR [keyword]
+
+         if evar_cls:
+            self._add_action (
+               evar_cls ( roverlay.strutil.unquote ( argstr ), lino )
+            )
+            return True
+         # else disabled evar action
+
+      elif keyword in self.KEYWORDS_DEPSTR:
+         depstr_cls = self.KEYWORDS_DEPSTR [keyword]
+
+         if depstr_cls:
+            self._add_action (
+               depstr_cls.from_namespace (
+                  self.namespace, 'all',
+                  roverlay.strutil.unquote ( argstr ),
+                  lino
+               )
+            )
+            return True
+         # else disabled
+
+      # -- end if
+      return False
+   # --- end of _add_as_keyworded_action (...) ---
+
    def feed ( self, _str, lino ):
       """Feeds this action block with input.
 
@@ -314,24 +357,15 @@ class RuleActionContext (
                   )
                )
 
-         elif len ( argv ) > 1 and (
-            self._add_as_info_action ( argv[0], argv[1], _str, lino )
+         elif len ( argv ) > 1 and argv[0] and (
+            self._add_as_info_action ( argv[0], argv[1], _str, lino ) or
+            self._add_as_keyworded_action ( argv[0], argv[1], _str, lino )
          ):
+            # "and argv[0]" not strictly necessary here
             pass
 
          else:
-            evar_cls = self.KEYWORDS_EVAR.get ( argv [0], None )
-
-            try:
-               if evar_cls:
-                  self._add_action (
-                     evar_cls ( roverlay.strutil.unquote ( argv [1] ), lino )
-                  )
-               else:
-                  raise ActionUnknown ( _str )
-
-            except IndexError:
-               raise ActionNeedsValue ( _str )
+            raise ActionUnknown ( _str )
    # --- end of feed (...) ---
 
    def create ( self ):


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

* [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/parser/context/, roverlay/packagerules/actions/
@ 2013-08-28  9:38 André Erdmann
  0 siblings, 0 replies; 6+ messages in thread
From: André Erdmann @ 2013-08-28  9:38 UTC (permalink / raw
  To: gentoo-commits

commit:     cc03c1b78e2f92191748d3f7d3b5a02df119a33a
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 28 09:34:40 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 28 09:34:40 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=cc03c1b7

package rule parser, depstr_ignore: minor changes

* don't unquote the dependency string
* store data in depconf->depstr_ignore, not depconf->depres_ignore

---
 roverlay/packagerules/actions/dependencies.py  | 2 +-
 roverlay/packagerules/parser/context/action.py | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/roverlay/packagerules/actions/dependencies.py b/roverlay/packagerules/actions/dependencies.py
index db4671d..f6233a2 100644
--- a/roverlay/packagerules/actions/dependencies.py
+++ b/roverlay/packagerules/actions/dependencies.py
@@ -163,7 +163,7 @@ class DependencyInjectAction ( DependencyVarAction ):
 # --- end of DependencyInjectAction (...) ---
 
 class DepStrIgnoreAction ( DependencyVarAction ):
-   CATEGORY_KEY   = 'depres_ignore'
+   CATEGORY_KEY   = 'depstr_ignore'
    ACTION_KEYWORD = CATEGORY_KEY
    CONVERT_VALUE_TO_DEPRESULT = False
 # --- end of DepStrIgnoreAction ---

diff --git a/roverlay/packagerules/parser/context/action.py b/roverlay/packagerules/parser/context/action.py
index 284d62e..c860d81 100644
--- a/roverlay/packagerules/parser/context/action.py
+++ b/roverlay/packagerules/parser/context/action.py
@@ -301,11 +301,10 @@ class RuleActionContext (
          depstr_cls = self.KEYWORDS_DEPSTR [keyword]
 
          if depstr_cls:
+            # don't unquote argstr
             self._add_action (
                depstr_cls.from_namespace (
-                  self.namespace, 'all',
-                  roverlay.strutil.unquote ( argstr ),
-                  lino
+                  self.namespace, 'all', argstr, lino
                )
             )
             return True


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

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

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

package rules: 'license' action

sets the LICENSE variable of an ebuild

---
 roverlay/packagerules/actions/evar.py          | 29 +++++++++++++++++++++-----
 roverlay/packagerules/parser/context/action.py |  1 +
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/roverlay/packagerules/actions/evar.py b/roverlay/packagerules/actions/evar.py
index 17f46fe..ea9d9f2 100644
--- a/roverlay/packagerules/actions/evar.py
+++ b/roverlay/packagerules/actions/evar.py
@@ -53,15 +53,34 @@ class EvarAction ( roverlay.packagerules.abstract.actions.PackageRuleAction ):
 
 # --- end of EvarAction (...) ---
 
+class EvarWithValueAction ( EvarAction ):
 
-class KeywordsEvarAction ( EvarAction ):
-   """A KeywordsEvarAction adds a KEYWORDS=... variable to a PackageInfo."""
+   @classmethod
+   def create_evar ( cls, value ):
+      return cls.EVAR_CLS ( value )
+   # --- end of create_evar (...) ---
 
-   def __init__ ( self, keywords, priority=1000 ):
-      super ( KeywordsEvarAction, self ).__init__ (
-         evar     = roverlay.ebuild.evars.KEYWORDS ( keywords ),
+   def __init__ ( self, value, priority=1000 ):
+      super ( EvarWithValueAction, self ).__init__ (
+         evar     = self.__class__.create_evar ( value ),
          priority = priority,
       )
    # --- end of __init__ (...) ---
 
+# --- end of EvarWithValueAction ---
+
+
+class KeywordsEvarAction ( EvarWithValueAction ):
+   """A KeywordsEvarAction adds a KEYWORDS=... variable to a PackageInfo."""
+
+   # could also set create_evar directly
+   EVAR_CLS = roverlay.ebuild.evars.KEYWORDS
+
 # --- end of KeywordsEvarAction ---
+
+class LicenseEvarAction ( EvarAction ):
+   """A LicenseEvarAction adds a LICENSE=... variable to a PackageInfo."""
+
+   EVAR_CLS = roverlay.ebuild.evars.LICENSE
+
+# --- end of LicenseEvarAction ---

diff --git a/roverlay/packagerules/parser/context/action.py b/roverlay/packagerules/parser/context/action.py
index c860d81..eafcfa6 100644
--- a/roverlay/packagerules/parser/context/action.py
+++ b/roverlay/packagerules/parser/context/action.py
@@ -53,6 +53,7 @@ class RuleActionContext (
    #
    KEYWORDS_EVAR = {
       'keywords' : roverlay.packagerules.actions.evar.KeywordsEvarAction,
+      'license'  : roverlay.packagerules.actions.evar.LicenseEvarAction,
    }
 
    # dict ( <keyword> => <depstr action> )


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

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-28  9:38 [gentoo-commits] proj/R_overlay:master commit in: roverlay/packagerules/parser/context/, roverlay/packagerules/actions/ André Erdmann
  -- strict thread matches above, loose matches on Subject: below --
2013-09-05 15:43 André Erdmann
2013-08-28  9:38 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-19 15:42 André Erdmann
2013-04-25 16:44 André Erdmann

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